如何在一列的计数中设置条件 [英] How to set condition in count of one Column
本文介绍了如何在一列的计数中设置条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表User和另一个Transaction。在Transaction表中,我将UserId引用为外键。在事务中,我有另一个名为status的列(基本上是Enum)。现在我需要那些在状态为3的交易中有两个以上条目的用户。
这就是我尝试过的事情
I have a table User and another Transaction. In Transaction table i have referenced UserId as foreign key. In transaction i have another column named status(which is basically Enum). Now I need those users which have more than two entries in transaction with status 3.
this is what I have Tried
Select * from Users U
Inner Join Transaction T On U.Id=T.UserId
having(Count (C.Status =1 ) >2)
任何人都可以帮助
谢谢
Can anyone help
Thanks
推荐答案
尝试
Select U.id from Users U
Inner Join Transaction T On U.Id = T.UserId
where T.status = 3
group by U.Id, T.status
having Count(T.status ) > 2
了解如何使用
: http://www.w3schools.com/sql/sql_having.asp [ ^ ]
Read how to use having
: http://www.w3schools.com/sql/sql_having.asp[^]
这篇关于如何在一列的计数中设置条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文