Please explain the SQL statements separately

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.