怎么样用SQL语句查询某一个表里面的某一个字段的总和

2024-11-30 01:44:34
推荐回答(4个)
回答1:

模板:

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;”

回答2:

select sum(字段) as 总和 from table

回答3:

select sum(字段名) from 表名

回答4:

sum函数