2 cxc233 cxc233 于 2017.09.19 19:32 提问

sql同一字段不同情况下的合并查找 5C
sql

表结构如下图

wtime money wmode wflag

1500883963 10000 0 1

1500889240 10000 0 0

1500889240 10000 5 1

时间戳 计算的主要字段 money的种类 支出还是收获

想要的结果格式,下面这样按天统计
w_time pay cash pay_5 cash_5
2017-07-25 1111 4151 456 4654
2017-08-25 2222 432 446 4123
2017-08-26 1234 324 222 4654
2017-08-27 1234 432 444 4654

自己的尝试
SELECT
FROM_UNIXTIME(wtime,'%Y-%m-%d') AS w_time,
IFNULL((SELECT SUM(money)
FROM log_win2
WHERE wflag = 1
AND wmode = 0
), 0) AS pay,
IFNULL((SELECT SUM(money)
FROM log_win2
WHERE wflag = 0
AND wmode = 0
), 0) AS cash,
IFNULL((SELECT SUM(money)
FROM log_win2
WHERE wflag = 0
AND wmode = 5
), 0) AS pay_1,
IFNULL((SELECT SUM(money)
FROM log_win2
WHERE wflag = 1
AND wmode = 5
), 0) AS cash_1
FROM log_win2
GROUP BY w_time

尝试结果图片说明

Csdn user default icon
上传中...
上传图片
插入图片