SELECT t1.CompanyName, COUNT(*) AS TotalOrder
FROM [table1] t1
INNER JOIN [table2] t2 ON t1.CompanyID = t2.CompanyID
GROUP BY t1.CompanyID
ORDER BY COUNT(*) DESC
我上面的代码已经只是希望显示最多的数量在gridview的底部和底部的数量较少,我该怎么做?
答案 0 :(得分:2)
尝试此查询。
SELECT t1.CompanyName, COUNT(t2.CompanyID) AS TotalOrder
FROM table1 t1 INNER JOIN table2 t2
ON t1.CompanyID = t2.CompanyID
GROUP BY t1.CompanyName
ORDER BY TotalOrder DESC
答案 1 :(得分:1)
据我所知,您的问题是您希望列出的公司名称按行号降序排列。如果有的话试试这个
SELECT t1.CompanyName, ROW_NUMBER() over (order by CompanyName) AS TotalOrder
FROM table1 t1 INNER JOIN table2 t2
ON t1.CompanyID = t2.CompanyID order by CompanyName desc