如何从数据库中显示1个名称

时间:2013-12-23 23:27:46

标签: c# asp.net sql

您好我的数据库中有这个,我希望只显示数据库中每个公司名称中的一个。

这是一个例如。

RecordID | CompanyName| OrderDate
1        |   Java     | 1 Dec 2013
2        |   Java      | 3 Dec 2013
3        |   ASP      | 10 Dec 2013

我想要的结果:

Java        
ASP         

而不显示

爪哇 Java的 ASP

怎么做?

3 个答案:

答案 0 :(得分:3)

SELECT CompanyName, COUNT(*) as TotalOrder
FROM Orders o
INNER JOIN Company c ON c.CompanyID = o.CompanyID
GROUP BY c.CompanyName
ORDER BY COUNT(*) DESC

答案 1 :(得分:3)

你应该试试

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

答案 2 :(得分:3)

这只是按计数分组和排序的问题:

select c.CompanyName, Count(*) as TotalOrder
from companytable c
inner join ordertable o on c.CompanyID = o.CompanyID
group by c.CompanyName
order by count(*) desc