Reputation: 39
I currently have a table called 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:
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. The label is to only appear for Product_Name that has the highest count.
My question now is how to use the following SQL statement to check the values from the database and enable the label to appear.
Upvotes: 0
Views: 503
Reputation: 215057
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.
Upvotes: 1
Reputation: 250
select top 1 Product_Name as 'Best Sellers', count(*) as 'Sales' from [Order_Details]
group by Product_Name
order by count(*) desc
Upvotes: 1