mysql order by 子查询 后面的结果 如何 也显示在结果集
问题描述
mysql order by 子查询 后面的结果 如何 也显示在结果集里
我的 mysql语句:
SELECT * FROM wht_user AS t1 WHERE pid =79 ORDER BY ( SELECT sum( `distribution_money` ) AS AGGREGATE FROM wht_distribution_detail AS t2 WHERE t1.id = t2.uid AND `puid` =79 AND `status` =4 GROUP BY `uid` ORDER BY `updatetime` DESC) DESC
如何 将 AGGREGATE 也显示在结果集里 或者有什么 更好的办法?
问题解答
回答1:求人不如求己 已解决:
SELECT * , COALESCE( SUM( `distribution_money` ) , 0.00 ) ASAGGREGATEFROM ( SELECT t1. * , t2 . * FROM `wht_user` AS t1 LEFT JOIN (SELECT `uid`, `distribution_money`FROM `wht_distribution_detail`WHERE `puid` = 79AND `status` = 4 ) AS t2 ON t1.`id` = t2.`uid`) AS s2WHERE `pid` =79GROUP BY `id`ORDER BY AGGREGATE DESC
相关文章:
1. python - flask jinjia2 中怎么定义嵌套变量2. docker Toolbox在win10 家庭版中打开报错3. javascript - 求教各位,本地HTML页面怎么在DIV中嵌套服务器上的页面内容?不用iframe。4. javascript - H5 video标签可以设置亮度吗?5. javascript - web拍照换脸技术原理6. javascript - jQuery中live事件在移动微信端下没有效果;代码如下7. html5 - git客服端安装报错8. html - 怎么实现css画半圆边框9. javascript - 回调函数和闭包的关系10. python - uwsgi+django的搭建问题