Heim  >  Fragen und Antworten  >  Hauptteil

Wie werden die nachfolgenden Ergebnisse der MySQL-Reihenfolge nach Unterabfrage auch im Ergebnissatz angezeigt?

Das Ergebnis der MySQL-Reihenfolge nach Unterabfrage wird auch im Ergebnissatz angezeigt

Mein MySQL-Statement:

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 

Wie zeige ich AGGREGATE im Ergebnissatz an? Oder gibt es eine bessere Möglichkeit?

阿神阿神2710 Tage vor603

Antworte allen(1)Ich werde antworten

  • ringa_lee

    ringa_lee2017-05-18 10:57:42

    求人不如求己 已解决:

    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 
    

    Antwort
    0
  • StornierenAntwort