如何编写此嵌套的sql server语句? [英] How to write this nested sql server statement?

查看:110
本文介绍了如何编写此嵌套的sql server语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想知道如何编写一个sql语句来做到这一点:

Hi,

I want to know how to write one sql statement to do like that:

select CommentID,AAA,CommentAddress  from Comments
where
AAA = select count(CommentSpamID) from CommentSpams where CommentID= CommentID



注意:
第一个语句中CommentID的值,我将在第二个语句中使用它.
希望你能理解我.

谢谢……



Notes:
the value of CommentID in first statement i will use it in second statement.
I hope you understand me .

thanks......

推荐答案



您可以像下面这样重新编写sql语句,

Hi,

You can re-wright the sql statement like the following,

select c.CommentID,c.AAA,c.CommentAddress
from Comments c
WHERE c.AAA = (select count(cs.CommentSpamID) from CommentSpams cs where cs.CommentID= c.CommentID)



希望这会有所帮助.

如果可以解决您的问题,请接受此作为答案.



Hope this will help.

Please accept this as answer if this solves your problem.


感谢上帝,:)

我解决了.

Thanks god , :)

I solved it.

select CommentID,(select count(CommentSpamID) from CommentSpams where Comments.CommentID= CommentSpams.CommentID) as CommentSpamNum ,CommentAddress from Comments


这篇关于如何编写此嵌套的sql server语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆