这个SQL该如何写
写SQL语句:
表1:CLASS
含有两个字段:ID,CLASSNAME,表结构如下:
ID CLASSNAME
1 A
2 B
3 C
4 D
表2:STUDENT
含有如下字段:SID,NAME,CLASSID
SID是主键,CLASSID是外键,可以通过它和CLASS表作连接。
SID NAME CLASSID
01 你 1
02 我 3
03 他 4
........
要求写一SQL语句,查询出A,B,C,D班各有多少学生。
SQL code:
select id,className,'人数'=(select count(1) from student where classid=class.id) from class
SQL code:
SELECT SUM(sid), classid from student GROUP BY classid
不好意思,写错了,是count(sid)
select c.classname,count(s.sid) from class c,student s where c.id=s.classid group by c.classname
SQL code:
select a.classname,b.fc
from (
select classid fcid,count(*) fc
from student
group by classid
) a
left join class b on a.fcid=b.id
SQL code
C
相关问答:
数据库某表,想将其中f1,f2两个字段的内容翻10倍,请教如何写法?
update tbl set f1= f1*10,f2= f2*10 where id=10451
这种写法会造成plsql卡死
不会吧,那个id=10451 的数据有多少啊~~~~
我估计sql是不 ......
users表
name companyId companyName
company表
companyId companyName
1 a公司
2 b公司
......
表中是这样,
部门号 部门信息
1 部门一
2 部门二
3 部门三
4& ......
怎么把下面的改成sql server的方法?
to_char(img_comm_metadata.scene_centre_time,'yyyy-mm-dd hh24:mm:ss')>='1990-10-13 09:41:20'
SQL code:
datediff(ss,'1990-10-13 09:41:20',img_ ......