高手请进来指教一下sql语句的问题,谢谢了

legu1 2010-03-11 05:49:18
select top 10 * from [Company] c
with (nolock) where c.AuditState=1 and c.userid in(select i.userid from company c,info i where c.userid=i.userid and c.UpdateTime>i.CreateTime)order by
case when c.[UserId] in(select c.UserId from Company c where [SubDomain]<>'' and [SubDomain] is not null )
then 1 else 2 end ,c.CompanyId desc;select count(*) from [Company] c with (nolock) where c.AuditState=1

这是我的sql语句,现在我要加个条件就是Info表,Info表中有一个UserId,它与Company中的UserId是对应的,我想再加个条件就是info.CreateTime<Company.UpdateTime,来查询数据,但是我加在哪里都不行,所以请大侠指教
...全文
144 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
legu1 2010-03-15
  • 打赏
  • 举报
回复
没有人知道吗?
legu1 2010-03-15
  • 打赏
  • 举报
回复
高手来指教一下啦
legu1 2010-03-15
  • 打赏
  • 举报
回复
company表字段:[CompanyId],[CategoryId],[CompanyName],[SiteUrl],[ProvinceId],[CityId],[AreaId],[ZoneId],[Street],[Address],[Contact],[Telephone],[Mobile],[Fax],[Email],[LogoPath],[AuditState],[UserId],[Summary],[Certificate],[Remark],[SortId],[ViewCount],[RatingValue],[CreateTime],[UpdateTime],[IsMember],[SubDomain]


info 表字段:i.[InfoId],i.[Title],i.[Body],i.[CategoryId],i.[UserId],i.[PictureId],i.[CreateTime],i.[UpdateTime],i.[State],i.[UserName],i.[SourceUrl],i.[SourceName],i.[SortId],i.[RatingValue],i.[ZoneId],i.[AreaId],i.[ProvinceId],i.[CityId],i.[InfoType],i.[MinPrice],i.[MaxPrice],i.[Phone],i.[Mobile],i.[AcceptAgent],i.[OnBoardTime],i.[ImgPhone]
ICrazyBoy 2010-03-15
  • 打赏
  • 举报
回复
lz SQL版里都还是想见见数据的优势的!所以贴出表结构和结果视图!你会得到答案!
legu1 2010-03-15
  • 打赏
  • 举报
回复
我按照楼上面的代码写的,为什么得出的每行内容都一样呢
dawugui 2010-03-12
  • 打赏
  • 举报
回复
楼主这样的描述很难理解.

最好给出完整的表结构,测试数据,计算方法和正确结果.


发帖注意事项
http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
叶子 2010-03-11
  • 打赏
  • 举报
回复

select top 10
*
from [Company] c ,
info i with ( nolock )
where c.AuditState = 1
and c.userid in ( select i.userid
from company c ,
info i
where c.userid = i.userid
and c.UpdateTime > i.CreateTime )
order by case when c.[UserId] in ( select c.UserId
from Company c
where [SubDomain] <> ''
and [SubDomain] is not null )
then 1
else 2
end ,
c.CompanyId desc ;
select count(*)
from [Company] c with ( nolock )
where c.AuditState = 1
SQL77 2010-03-11
  • 打赏
  • 举报
回复
select 
top 10 *
from [Company] c with (nolock) ,INFO I
where c.AuditState=1 and c.userid=i.userid and c.UpdateTime>i.CreateTime
order by
case when c.[UserId] in(select c.UserId from Company c where [SubDomain]<>'' and [SubDomain] is not null )
then 1 else 2 end ,c.CompanyId desc;select count(*) from [Company] c with (nolock) where c.AuditState=1
?
东那个升 2010-03-11
  • 打赏
  • 举报
回复
select top 10 * 
from [Company] c,info i
where c.AuditState=1
and c.userid=i.userid
and c.UpdateTime>i.CreateTime
order by case when c.[SubDomain]<>'' and c.[SubDomain] is not null then 1 else 2 end ,c.CompanyId desc

这样。。。

34,590

社区成员

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

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