mysql order by 子查詢 後面的結果 如何 也顯示在結果集
阿神
阿神 2017-05-18 10:55:42
0
1
608

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 ) AS
AGGREGATE
FROM (

    SELECT t1. * , t2 . *
    FROM `wht_user` AS t1
    LEFT JOIN (
        SELECT `uid`, `distribution_money`
        FROM `wht_distribution_detail`
        WHERE `puid` = 79
        AND `status` = 4
    ) AS t2 ON t1.`id` = t2.`uid`
) AS s2
WHERE `pid` =79
GROUP BY `id`
ORDER BY AGGREGATE DESC 
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!