Mysql (7) in-depth select query bitsCN.com
Mysql (7) in-depth select query
Related links:
Mysql (1) installation of mysql
Http: // database/201210/162314 .html;
Mysql-related operations (2)
Http: // database/201210/162315 .html;
Mysql operations on data tables (3)
Http: // database/201210/162316 .html;
Mysql (4) Data Table query operations
Http: // database/201210/162317 .html;
Mysql operations (5)
Http: // database/201210/162318 .html;
Mysql (6) string pattern matching
Http: // database/201210/163969 .html
I. table alias
SELECT * FROM pet p order by p. age;
This is to sort the queried data by the table's age.
If you want to pair a pet in a pet table, you can use the alias of the table as follows:
SELECT p1.name, p1.sex, p2, name, p2.sex FROM pet AS p1, pet AS p2 WHERE p1.species = p2.species AND p1.sex = "M" AND p2.sex = "F ";
This statement means pairing by species, with the gender M and F;
II. column alias
Query the pet name and type (directly reference the column name ).
SELECT name, species FROM pet order by name, species;
Similar:
SELECT name, species FROM pet order by 1, 2;
This is the same as the above functions.
You can also name a column.
SELECT name AS n, species AS s FROM pet order by n, s;
This function is the same as the preceding statement.
Use the column alias in the clause:
SELECT species, COUNT (*) AS total FROM pet group by species HAVING total> 1;
BitsCN.com