Home > Backend Development > PHP Tutorial > 请大神分开解释一下SQL语句

请大神分开解释一下SQL语句

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:10:58
Original
1019 people have browsed it

这句sql是什么意思,请大神指教

<code>SELECT `sid`,count(*) AS count FROM `hx_shop_period` GROUP BY sid ORDER BY count desc LIMIT 5</code>
Copy after login
Copy after login

请大神分开解释一下SQL语句

回复内容:

这句sql是什么意思,请大神指教

<code>SELECT `sid`,count(*) AS count FROM `hx_shop_period` GROUP BY sid ORDER BY count desc LIMIT 5</code>
Copy after login
Copy after login

请大神分开解释一下SQL语句

查找 hx_shop_peried表,根据条件group by sid(以sid为分组)查找出sid字段和sid出现的次数,生成一个结果集。
然后对这个结果集进行降序排序,取出前5行

非大神...

1. SELECT 很好理解,指定要返回哪些值,这里是返回 sid 和 count

2. FROM 也很好理解,从 hx_shop_period 这张表里返回...

3. 那么 count(*) AS count 怎么理解?

count(column_name) 是用于计算数量的,括号内是列的名字,如果为*表示表中的记录数。

但这里与 GROUP BY 连用,意思是计算各个 sid 的数量。

4. ORDER BY / LIMIT 都很好理解就是按照什么排序,和限制返回数目

连起来就是从 hx_shop_period 这张表里返回5条 sid 和 sid 的数量的消息,结果按照数量降序。

聚合sid,sid一样的数量加一起放一个字段,由数量降序只取5条记录

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template