7.0
2 5.0 0 1.0
3 4.0 1 4.0
4 3.0 1 0.0
I want to get top 3 row of the name user_name and number of all the row data.
How can I do this? I tried the following query but its showing error
SELECT user_name,count(*)
FROM trade_graph
GROUP BY user_name
ORDER BY count(*) DESC;
A:
You need to use an aggregate function on your inner SELECT. You could use MAX() or COUNT(*) to get the desired results:
SELECT user_name, MAX(count)
FROM trade_graph
GROUP BY user_name
ORDER BY MAX(count) DESC;
For MySQL 8+, you can use ROW_NUMBER():
SELECT t.user_name, ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC)
FROM trade_graph t
For over a decade, researchers have known about a mysterious and lethal rodent disease called Cache Valley Disease (CVD), a fatal ailment that seems to attack only ground squirrels.
A new study by researchers from the University of Utah and Texas A&M University suggests the disease is caused by a new and unknown bacterium, and it is already affecting people in the Southwest.
The new study, published in the American Journal of Tropical Medicine and Hygiene, makes that case.
“People have been seeing dead squirrels in the West for years and have assumed it was a squirrel virus
Related links:
Comments