In the MYSQL joint query, GROUP_CONCAT, MAX, and year use bitsCN.com
This is what happened yesterday. it was encountered when I wrote a resume searcher. I checked a lot of information. here I will record some of the problems encountered in the SELECT joint query with a solution.
The first example is as follows:
$ SQL = "";
$ SQL. = "SELECT ";
$ SQL. = "". T _. "person_info.personid ,";
$ SQL. = "". T _. "person_info.personname ,";
$ SQL. = "". T _. "person_info.sex ,";
$ SQL. = "year (". T _. "person_info.birthday) AS age ,";
$ SQL. = "MAX (". T _. "person_edu.education) AS xueli ,";
$ SQL. = "". T _. "person_edu.school ,";
$ SQL. = "GROUP_CONCAT (". T _. "person_edu. 'subobject '),";
$ SQL. = "". T _. "person_info.shi1 ";
$ SQL. = "FROM ";
$ SQL. = "". T _. "person_info ";
$ SQL. = "LEFT JOIN". T _. "person_edu ON". T _. "person_info.personid =". T _. "person_edu.personid ";
$ SQL. = "WHERE 1 = 1 ";
$ SQL. = "AND". T _. "person_info.personid = '". $ autoid ."'";
$ SQL. = "GROUP BY personid ";
GROUP_CONCAT () is a function provided BY the MySQL database. it is usually used together with group by to form a result set composed of all the subject results of the same personid and separated BY commas, only fields of the character type are supported. Special writing is required for the integer type, because it is not studied.
MAX is the maximum value in the integer type. it is used here to obtain the highest education level (educational level Dictionary). it is used together by group.
Year and month are all extracted from the time type, such as year and month. here I extract year from the birth day to calculate the age (the so-called year after year, the age is still accurate)
In addition, group by means that only one record is displayed. for example, there may be many records in the database for a certain individual's educational qualifications, however, if the result is displayed in the combined search result on the front end, I need to merge the results and obtain only the highest one.
This article is from the "Golden Pig's PHP growth path" blog
BitsCN.com