Home >Database >Mysql Tutorial >What are the MySql query methods?
insert into B select * from A;//将A表的信息通过查询新增到B表中去
count;//返回到查询的数据总和
sum;//返回到查询的数据总和(只对数字有意义)
avg/max/min;//返回查询数据的平均值/最大值/最小值(只对数字有意义)
select * from 表名 group by 分组条件;
having;Having can be used to conditionally filter the results grouped by group by. where is executed before grouping. If you want to conditionally filter the results after grouping, you need to use having (used with group by). For example: Find the average salary of each role, except Wu Jiu. This sentence can be rewritten as: "Specify the conditions before grouping-remove Wu Jiu, and then calculate the average salary.".
The first way of writing: select * from table name 1, table name 2;joint query (more important) is a multi-table query, and the previous queries are all single-table queries. The core operation in multi-table query---Cartesian product. The Cartesian product operation is to combine each record of the two tables to obtain a new set of records.The second way of writing: select * from table name 1 join table name 2 on conditions;
select s1.student_id,s1.score,s2.score from score as s1,score as s2 where s1.student_id=s2.student_id and s1.course_id=3 and s2.course_id=1 and s1.score>s2.score;
union;//这个可自动去重 union all;//这个不可自动去重
select * from course where id<3 union select * from course where name='英文';Or use or to achieve
select * from course where id<3 or name='英文';
The above is the detailed content of What are the MySql query methods?. For more information, please follow other related articles on the PHP Chinese website!