帮忙把这个sql优化一下,在线等~

xuxubaby 2011-08-31 11:31:19
SELECT comid,CompanyName,addtime,[status] FROM (select *, ROW_NUMBER() OVER (order by [status] asc)
AS RowNumber FROM job_company
where comid in(select comid from job_job where [status]=1) and addtime='2011-08-31' and addtime>='2011-08-18') t
...全文
133 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuxubaby 2011-08-31
  • 打赏
  • 举报
回复
哦了 ,3q各位。结贴 ~
xuxubaby 2011-08-31
  • 打赏
  • 举报
回复
我建了一个组合索引,status,addtime这2个字段。
中国风 2011-08-31
  • 打赏
  • 举报
回复
addtime列上建上索引
中国风 2011-08-31
  • 打赏
  • 举报
回复
select 
comid,CompanyName,addtime,ROW_NUMBER() OVER (order by [status] asc)AS RowNumber --這列有沒有用到,只用排序用order by
FROM
job_company AS a
where exists(select comid from job_job where [status]=1 AND comid=a.comid)
and (addtime>='2011-08-18' OR addtime='2011-08-31' )
nvhaixx 2011-08-31
  • 打赏
  • 举报
回复
SELECT comid, CompanyName, addtime, status
FROM job_company
where comid in (select t.comid from job_job t where t.status = 1)
and (addtime = '2011-08-31' or addtime >= '2011-08-18')
AcHerat 元老 2011-08-31
  • 打赏
  • 举报
回复
SELECT comid,CompanyName,addtime,[status],ROW_NUMBER() OVER (order by [status] asc) AS RowNumber 
FROM job_company t
where exists (select 1 from job_job where [status]=1 and comid = t.comid)
and addtime='2011-08-31'
or addtime>='2011-08-18'
--其实也不应该用or,你只要大于俩日期最小的就可以,即 addtime>='2011-08-18'
--小F-- 2011-08-31
  • 打赏
  • 举报
回复
SELECT
comid,CompanyName,addtime,[status]
FROM
(select *, ROW_NUMBER() OVER (order by [status] asc) AS RowNumber FROM job_company)t
where
exists(select 1 from job_job where comid=t.comid and [status]=1)
and
addtime='2011-08-31'
and
addtime>='2011-08-18') t
AcHerat 元老 2011-08-31
  • 打赏
  • 举报
回复
SELECT comid,CompanyName,addtime,[status],ROW_NUMBER() OVER (order by [status] asc) AS RowNumber 
FROM job_company
where comid in (select comid from job_job where [status]=1)
and addtime='2011-08-31'
and addtime>='2011-08-18' --这两个日期应该留一个最大的吧!
xuxubaby 2011-08-31
  • 打赏
  • 举报
回复
哦 这里应该换成 or ,主要问题是出在in 上 ,用了in ,查询速度就慢了很多.
geniuswjt 2011-08-31
  • 打赏
  • 举报
回复

--没看出来哪里用到row_number(),固去掉;in改为exists;addtime后面多余的去掉。如下:
SELECT comid,CompanyName,addtime,[status] FROM job_company a
where exists(select 1 from job_job where [status]=1 where comid=a.comid)
and addtime='2011-08-31'
geniuswjt 2011-08-31
  • 打赏
  • 举报
回复

and addtime='2011-08-31' and addtime>='2011-08-18'

这里啥意思?

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧