BH XB CJ
01 男 4
02 男 3
03 女 5
04 男 5
05 女 4
能否只查一次,就能查出以下结果:
总人数:5
男生数:3
女生数:2
男生总成绩:12
一次能否查出来,用什么语句?多谢了!!
01 男 4
02 男 3
03 女 5
04 男 5
05 女 4
能否只查一次,就能查出以下结果:
总人数:5
男生数:3
女生数:2
男生总成绩:12
一次能否查出来,用什么语句?多谢了!!
(select count(*)from Table where xb='男')as 男生数,
(select count(*)from Table where xb='女')as 女生数,
(select sum(CJ)from Table where xb='男')as 男生总成绩
请问怎么取这四个值呀
(select count(*)from Table where xb='男')as 男生数,
(select count(*)from Table where xb='女')as 女生数,
(select sum(CJ)from Table where xb='男')as 男生总成绩
是不是这样写呀adoquery1.FieldByName('总人数').AsString;
adoquery1.FieldByName('男人数').AsString;
adoquery1.FieldByName('女生数').AsString;
adoquery1.FieldByName('男人总成绩').AsString;
from tab
where 1=1
group by xb
with cube'
______________
查出后,四个值被升序排列了,如
2
3
5
12
怎样准确得到呢?
下一步知道怎么分别取出值了吧?
var
i: integer;
begin
With ADOQuery1 do
begin
Close;
SQL.Text := '(select Count(*) as 总人数 from main) union all (select Count(*) as 男生数 from main where xb=''男'') union all (select Count(*) as 女生数 from main where xb=''女'') union all (select Sum(cj) as 男生总成绩 from main where xb=''男'')';
Open;
First;
while (not eof) do
begin
ShowMessage(FieldValues['总人数']);
Next;
end;
end;
end;