子查询 如果出现这种情况 怎么办?

hql5202004 2010-11-06 03:49:00
子查询 如果出现这种情况 怎么办?
先贴上代码:
select * from (select row_number() over(order by userKeywordsID) as Rownum
,userID,title
from 表A where status=1 and statusPlan=1
and (budgetMoneyLimit=0 or budgetMoneyLimit<= (select clickAllMoney from VM_表B
where VM_表B.userID =表A.userID)) group by userKeywordsID,userID,title)a
where (Rownum between 1 and 10)


其中 子查询 budgetMoneyLimit<= (select clickAllMoney from VM_表B
where VM_表B.userID =表A.userID)

而 (select clickAllMoney from VM_表B
where VM_表B.userID =表A.userID) 这语句 有时候查询结果是没有记录的 。导致 budgetMoneyLimit<= 没有记录的??

这样语句 就查不到东西了?如何改动。。。?
...全文
95 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
飘零一叶 2010-11-07
  • 打赏
  • 举报
回复
select * from (select row_number() over(order by userKeywordsID) as Rownum  
,userID,title
from 表A where status=1 and statusPlan=1
and (budgetMoneyLimit=0 or budgetMoneyLimit<= (select clickAllMoney from VM_表B
where VM_表B.userID =表A.userID and clickAllMoney is not null)) group by userKeywordsID,userID,title)a
where (Rownum between 1 and 10)


-晴天 2010-11-07
  • 打赏
  • 举报
回复
budgetMoneyLimit<= (select clickAllMoney from VM_表B where VM_表B.userID =表A.userID)
select * from (select row_number() over(order by userKeywordsID) as Rownum,userID,title
from 表A where status=1 and statusPlan=1
and (budgetMoneyLimit=0 or
exists(select 1 from VM_表B where VM_表B.userID =表A.userID and 表A.budgetMoneyLimit<=clickAllMoney))
group by userKeywordsID,userID,title)a where (Rownum between 1 and 10)
xman_78tom 2010-11-07
  • 打赏
  • 举报
回复
budgetMoneyLimit<= isnull((select clickAllMoney from VM_表B
where VM_表B.userID =表A.userID), budgetMoneyLimit)
「已注销」 2010-11-06
  • 打赏
  • 举报
回复
TRY~~~
select * from (select row_number() over(order by userKeywordsID) as Rownum
,userID,title
from 表A where status=1 and statusPlan=1
and (budgetMoneyLimit=0 or EXISTS (select NULL from VM_表B
where VM_表B.userID =表A.userID AND 表A.budgetMoneyLimit<= budgetMoneyLimit)
) group by userKeywordsID,userID,title)a
where (Rownum between 1 and 10)

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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