SQL group query statement for relative data

Source: Internet
Author: User

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;

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.