首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

高手解决SQL语句中动态给WHERE条件解决方法

2012-02-17 
高手解决SQL语句中动态给WHERE条件select distinct UserInfoID from HB_UserInfo order by UserInfoIDsele

高手解决SQL语句中动态给WHERE条件
select distinct UserInfoID from HB_UserInfo order by UserInfoID
  
  select Sum(ReadCount) as readcount,HB_UserInfo.UserName from HB_Post, HB_UserInfo where HB_Post.UserInfoID='12'
  
  select UserName from HB_UserInfo where UserInfoID='12'

我要三句变一句 下面两句中的UserInfoID要改成遍历第一句中的结果集 动态给 比如:第一句结果集{1,2,3},那下面2句中的UserInfoID为1,2,3;结果是3条记录 

有高手帮忙吗 


[解决办法]
select Sum(ReadCount) as readcount,HB_UserInfo.UserName from HB_Post, HB_UserInfo where HB_Post.UserInfoID in(select distinct UserInfoID from HB_UserInfo order by UserInfoID)
 
select UserName from HB_UserInfo where UserInfoID in(select distinct UserInfoID from HB_UserInfo order by UserInfoID)
[解决办法]

SQL code
select Sum(ReadCount) as readcount,HB_UserInfo.UserName from HB_Post, HB_UserInfo where HB_Post.UserInfoIDin(select distinct UserInfoID from HB_UserInfo)
[解决办法]
select Sum(ReadCount) as readcount,HB_UserInfo.UserName from HB_Post, HB_UserInfo where HB_Post.UserInfoID
in(select distinct UserInfoID from HB_UserInfo)

热点排行