易截截图软件、单文件、免安装、纯绿色、仅160KB

这个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


相关问答:

求sql语句将数据库表某些字段的内容翻10倍

数据库某表,想将其中f1,f2两个字段的内容翻10倍,请教如何写法?
update tbl set f1= f1*10,f2= f2*10 where id=10451
这种写法会造成plsql卡死
不会吧,那个id=10451 的数据有多少啊~~~~

我估计sql是不 ......

sql 存储过程 动态表 DateTime数据类型 添加问题

我的数据库的表是动态的表,在添加数据的时候有一个字段是DATETIME数据类型的,下面是存储过程
if exists (select * from sysobjects where name='proc_ADD_Order')
drop proc proc_ADD_Order
go
......

ORACLE sql语句的问题

  现在有表A(barcode varchar2,length number),B(barcode varchar2,serial number)其中barcode关联A:B为1:n

有如下sql语句
insert into a values('b1',10)
insert into a values( ......

求一sql语句。

表中是这样,
部门号    部门信息
  1        部门一
  2        部门二
  3        部门三
  4& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号