What does this SQL statement mean? Please kindly advise {code ...}
What does this SQL statement mean?
SELECT `sid`,count(*) AS count FROM `hx_shop_period` GROUP BY sid ORDER BY count desc LIMIT 5
Reply content:
What does this SQL statement mean?
SELECT `sid`,count(*) AS count FROM `hx_shop_period` GROUP BY sid ORDER BY count desc LIMIT 5
Searchhx_shop_periedTable, which is located Based on the condition group by sid (grouped by sid)sidThe number of times the field and sid appear to generate a result set.
Then sort the result set in descending order and retrieve the first five rows.
Not a great god...
1. SELECT is easy to understand. It specifies the values to be returned. Here, return sid and count2. FROM is also easy to understand. Return FROM the hx_shop_period table... 3. so how do I understand count (*) AS count?
Count (column_name) is used to calculate the quantity. It is the column name in parentheses. If it is *, it indicates the number of records in the table.
However, it is used with group by to calculate the number of each sid.
4. order by/LIMIT is a good understanding of the sorting BY and the LIMIT on the number of returned results.
After the connection, five messages of sid and sid are returned from the hx_shop_period table. The result is sorted in descending order.
Aggregate sid, add a field with the same number of sid, and take only five records in descending order of the number