Display each DISTINCT Field Value only once using loop

前端 未结 3 980
夕颜
夕颜 2021-01-26 04:36
SELECT listTitle, listLength, listCmt, listDt, mBCFName, mBCLName, moAmt, moDtOff
FROM User U, Listing L, Merchant M, MerchantOffer MO
WHERE U.uID = L.uID
and L.listID =         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-26 05:34

    This is not that easy - the question is what to show for the other field (for example the "mBCFName" field - "Amanda" OR "John")?

    use the "Group by" SQL statement and then define the rules (max,min,avg, GROUP_CONCAT ...) to select the other rows - Example:

    SELECT listTitle, min(listLength), min(listCmt), min(listDt), GROUP_CONCAT(mBCFName), min(mBCLName), min(moAmt), min(moDtOff)
    FROM User U, Listing L, Merchant M, MerchantOffer MO
    WHERE U.uID = L.uID
      and L.listID = MO.listID
      and M.mID = MO.mId
    GROUP BY listTitle
    ORDER BY listDt DESC;
    

提交回复
热议问题