簡體   English   中英

按總和t-sql排序

[英]order by sum t-sql

select 
    w.firstName, w.lastName, w.fbId, q.userId, 
    SUM(q.bidCount) as sumOfBids
from 
    geopl_kubetiAuct.firstWeekBids as q 
join 
    geopl_kubetiAuct.Users w on q.userId = w.Id
where 
    q.bidedItem = 'laptop' 
group by 
    w.firstName, w.lastName, w.fbId, q.userId

這將選擇所有符合此要求的用戶。 如何選擇前2個sumOfBids

我已經order by sumOfBids top 2 descgroup by order by sumOfBids top 2 desc添加了order by sumOfBids top 2 desc但是它不起作用

SELECT TOP 2 w.firstName,
             w.lastName,
             w.fbId,
             q.userId,
             Sum(q.bidCount) AS sumOfBids
FROM   geopl_kubetiAuct.firstWeekBids AS q
       INNER JOIN geopl_kubetiAuct.Users w
               ON q.userId = w.Id
WHERE  q.bidedItem = 'laptop'
GROUP  BY w.firstName,
          w.lastName,
          w.fbId,
          q.userId
ORDER  BY sumOfBids DESC 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM