SELECT
b.id,
b.book_name,
sum( IF ( o.create_time > 0 o.create_time 9999999999, o.price, 0 ) ) today_pay_money,
sum( IF ( o.create_time > 0 o.create_time 9999999999, 1, 0 ) ) today_pay_num,
sum( IF ( o.create_time > 999 o.create_time 9999, o.price, 0 ) ) yesterday_pay_money,
sum( IF ( o.create_time > 999 o.create_time 9999, 1, 0 ) ) yesterday_pay_num,
sum(o.price) total_pay_money,
sum( IF ( o.create_time > 9999 o.create_time 99999, 1, 0 ) ) total_pay_num,
( SELECT SUM( total_score ) FROM book_reward_log WHERE book_id = b.id ) total_score,
(
SELECT
CONCAT_WS(
',',
SUM( IF ( create_time > 0 create_time 998, score, 0 ) ),
SUM( IF ( create_time > 9999 create_time 99998, score, 0 ) ),
SUM( IF ( create_time > 99999 create_time 999998, score, 0 ) )
)
FROM
book_consume_log
WHERE
book_id = b.id
) score
FROM
book_book b
LEFT JOIN book_orders o ON b.id = o.bid
GROUP BY
b.id
更多关于MySQL相关内容感兴趣的读者可查看本站专题:《MySQL查询技巧大全》、《MySQL常用函数大汇总》、《MySQL日志操作技巧大全》、《MySQL事务操作技巧汇总》、《MySQL存储过程技巧大全》及《MySQL数据库锁相关技巧汇总》