34,590
社区成员
发帖
与我相关
我的任务
分享
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' )
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'
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
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' --这两个日期应该留一个最大的吧!
--没看出来哪里用到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'
and addtime='2011-08-31' and addtime>='2011-08-18'