SQL group query statement for relative data
/*
|
Section | Province | Area | Zone | Postcode | Cardtype | Telco |
| 1879728 | Qinghai | Republic | 0974 | 813000 | Move 187 Cards | Move |
| 1879741 | Hunan | Changsha | 0731 | 410000 | Move 187 Cards | Move |
| 1889927 | Xinjiang | Hotan | 0903 | 848000 | Xinjiang Mobile Global Pass Card | Move |
| 1889930 | Xinjiang | Hami | 0902 | 839000 | Xinjiang Mobile Global Pass Card | Move |
| 1893300 | Guangdong | Foshan | 0757 | 528100 | Guangdong Telecom CDMA Card | Telecom |
| 1893319 | Guangdong | guangzhou | 020 | 510000 | Guangdong Telecom CDMA Card | Telecom |
*/
$sql = "SELECT * from table where XXX Group is left (section, 3)";
/*
Left
(Str,len) syntax
Returns the leftmost Len character of the string str.
MySQL Tutorials > select Left (' Foobarbar ', 5);
-> ' Fooba '
The function is multiple-byte reliable.
GROUP BY
Group
The common database tutorial has the ability to analyze data based on specific columns of the table.
You can group rows according to the groups defined in the GROUP BY clause. In its simplest form, a group consists of columns called grouped columns. The column names in the SELECT clause must be grouped columns or column functions. The column function returns a result for each group defined by the groups by clause
Select Sex,max (Ages) as age from table group by sex;