Heim > Datenbank > MySQL-Tutorial > sql 对相对数据进行分组查询语句

sql 对相对数据进行分组查询语句

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-07 17:47:26
Original
1048 Leute haben es durchsucht

可按照在 GROUP BY 子句中定义的组对行进行分组。以其最简单的形式,组由称为分组列的列组成。 SELECT 子句中的列名必须为分组列或列函数。列函数对于 GROUP BY 子句定义的每个组各返回一个结果

sql 对相对数据进行分组查询语句
/*
|

section | province | area   | zone | postcode | cardtype                 | telco  |

| 1879728 | 青海      | 共和         | 0974 | 813000   | 移动187卡                   | 移动   |
| 1879741 | 湖南      | 长沙         | 0731 | 410000   | 移动187卡                   | 移动   |
| 1889927 | 新疆      | 和田         | 0903 | 848000   | 新疆移动全球通卡            | 移动   |
| 1889930 | 新疆      | 哈密         | 0902 | 839000   | 新疆移动全球通卡            | 移动   |
| 1893300 | 广东      | 佛山         | 0757 | 528100   | 广东电信cdma卡              | 电信   |
| 1893319 | 广东      | 广州         | 020  | 510000   | 广东电信cdma卡              | 电信   |

*/

$sql ="select * from table where xxx group by left(section, 3)";

/*

left(str,len) 语法
返回字符串str的最左面len个字符。
> select left('foobarbar', 5);
        -> 'fooba'


该函数是多字节可靠的。

group by
分组
通用具有基于表的特定列对数据进行分析的能力。
可按照在 group by 子句中定义的组对行进行分组。以其最简单的形式,组由称为分组列的列组成。 select 子句中的列名必须为分组列或列函数。列函数对于 group by 子句定义的每个组各返回一个结果

select  sex,max(ages)  as  age  from  table  group  by  sex;

Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage