[英]How to display label based on maximum count in database? ASP.NET C#
I currently have a table called Order_Details. 我目前有一个名为Order_Details的表。 Here, all records are stored like the example shown below:
在这里,所有记录的存储方式如下例所示:
OrderID Product_Name
1 Alpha
2 Alpha
3 Alpha
4 Bravo
5 Charlie
I have used the following sql statement to determine which record occurs the most: 我已使用以下sql语句来确定哪个记录出现得最多:
select top 1 Product_Name, count(*) from [Order_Details]
group by Product_Name
order by count(*) desc
Output is below: 输出如下:
Product_Name (No column name)
Alpha 10
Right now, I would like to enable a Label called "Best Sellers" to appear after executing the query above. 现在,我想启用一个名为“ Best Sellers”的标签,以在执行上面的查询后显示。 The label is to only appear for Product_Name that has the highest count.
标签仅针对具有最高计数的Product_Name出现。
My question now is how to use the following SQL statement to check the values from the database and enable the label to appear. 现在的问题是如何使用以下SQL语句从数据库中检查值并启用标签。
select top 1 Product_Name as 'Best Sellers', count(*) as 'Sales' from [Order_Details]
group by Product_Name
order by count(*) desc
select top 1 Product_Name, count(*) as cnt, 'Best Seller' as label1 from [Order_Details]
group by Product_Name
order by count(*) desc
See the fiddle here. 在这里看到小提琴 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.