模板:
1、“select s.id,s.name,t.id,t.name from student s left join teacher t on t.id=s.teacher_id;”
2、“select s.id as student_id ,s.name as student_name,t.id as teacher_id,t.name as teacher_name from student s left join teacher t on t.id=s.teacher_id;”
另外,查询一个表中某个字段相同的数据的方法:
也是拿student来做例子,查询有相同老师的student。
“select * from students group by teacher_id HAVING COUNT(teacher_id)>1;”
select sum(字段) as 总和 from table
select sum(字段名) from 表名
sum函数