[英]Get one larger column from another columns in same table sql
I want to select a name
that has more received
than he sent
from my table called data_saver
我想给 select 一个
name
,该名称比他received
我的表中sent
的数据多,称为data_saver
name | Received | Sent
-----------------------------
Kiki | 7 | 0
Kim | 4 | 5
Lee | 2 | 1
John | 3 | 6
In this case Kiki
and Lee
will be selected.在这种情况下,将选择
Kiki
和Lee
。 Please help me for selecting this in MySQLi
table, Any help is appreciated.请帮助我在
MySQLi
表中选择这个,任何帮助表示赞赏。
If Received
equals 1 when received otherwise it equals 0, if Sent
equals 1 when sent otherwise it equals 0, than you only need to sum()
the columns like this:如果接收时
Received
等于 1,否则它等于 0,如果发送时Sent
等于 1,否则它等于 0,那么你只需要sum()
如下所示的列:
Select a.name , sum(a.Received) Received, sum(a.Sent) Sent
from data_saver a
group by a.name
having sum(a.Received) > sum(a.Sent)
and a.name ='Kiki'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.