I want to select a name
that has more received
than he sent
from my table called 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. Please help me for selecting this in MySQLi
table, Any help is appreciated.
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:
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'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.