简体   繁体   English

从同一表 sql 中的另一列中获取一个更大的列

[英]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.在这种情况下,将选择KikiLee 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.

相关问题 sql连接中存在相同名称的两列时,如何从一个表列获取值 - How to get value from one table column when two columns of the same name exist in an sql join SQL查询将两列与另一张表中的一列进行比较(并获得两个值) - SQL Query to compare two columns with one column from another table (and get two values) 如何将SQL表中的2列连接到另一个SQL表中的一列? - How to join 2 columns in a SQL table to one column in another SQL table? 如何从一个表中获取所有列,而从另一张表中仅获取具有ID的一列? -MySQL - How to get all columns from one table and only one column from another table with ID ? - MySql SQL查询可从一个表中检索所有列,而从另一表中检索一个列 - SQL Query that retrieves all columns from one table and one column from the another 将时间戳从 SQL 表的一列转换为同一表另一列中的日期 - Converting timestamp from one column of an SQL table to dates in another column of the same table 将一个表的两列连接到另一表的同一列 - Join two columns of one table to the same column of another table Sequelize将一张表的两列连接到另一张表的同一列 - Sequelize join two columns of one table to the same column of another table 将数据从另一表的一列插入到同一表的多列中 - Inserting data into multiple columns of same table from one column of another table 如何从一个表数据复制列到另一表并在mysql中同时插入更多列? - how to copy column from one table data to another table and insert more columns same time in mysql?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM