作 者:hymen1
所属论坛:Delphi
问题点数:20
回复次数:5
发表时间:2001-10-17 8:34:59
有点问题:
SQL.Add('SELECT main.no1,main.name,SUM(juan.ml) AS ml ');
SQL.Add('From main LEFT JOIN juan ON main.No1=juan.No1 ');
SQL.Add('where ml>=:a ');
SQL.Add('Group By main.no1,main.name');
SQL.Add('order by ml desc');
parambyname('a').asinteger:=strtoint(edit1.text);
// parambyname('b').asinteger:=strtoint(edit2.text);
是好的。当改为:
SQL.Add('where ml>=:a and ml<=:b');时
查询的结果有错误?
搞不清楚怎么回事?
出现的问题为:部分结果累计时,没有全部累计,
但当 ml>=:a 时是正常的,
ml<=:b时,就累加出现不全了???
用haning就跟不行了
应如何如下的数据库 查询得到 我想要的数据集呢?
数据库结构如下:
表1:
no1(关健字) nane sex
1 aa f
2 bb f
3 cc m
4 ab f
表2:
no2(关键字) no1 name ml
1 1 aa 100
2 1 aa 200
3 2 bb 200
4 2 bb 100
5 3 cc 500
要得到的 数据集
no1 name sum(ml)
1 aa 300
2 bb 300
3 cc 500
4 ab 0
那么查询语句应该怎样写了!!
9 个解决方案
#1
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
#2
SQLServer数据库
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
#3
SQLServer数据库
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
#4
gz
#5
SQLServer数据库
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
#6
#7
SQLServer数据库
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
Access数据库
Select No1,Name,
Iif((Select Sum(ml) From juan Where No1=Main.No1) is Null,0,(Select Sum(ml) From juan Where No1=Main.No1)) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
Access数据库
Select No1,Name,
Iif((Select Sum(ml) From juan Where No1=Main.No1) is Null,0,(Select Sum(ml) From juan Where No1=Main.No1)) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
#8
我也没太看出哪里有不对的地方。 你试将SUM(juan.ml) AS ml 后的AS ml 的ml 换个名试试。
#9
up
#1
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
#2
SQLServer数据库
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
#3
SQLServer数据库
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
#4
gz
#5
SQLServer数据库
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
#6
#7
SQLServer数据库
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
Access数据库
Select No1,Name,
Iif((Select Sum(ml) From juan Where No1=Main.No1) is Null,0,(Select Sum(ml) From juan Where No1=Main.No1)) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
Select No1,Name,
IsNull((Select Sum(ml) From juan Where No1=Main.No1),0) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
Access数据库
Select No1,Name,
Iif((Select Sum(ml) From juan Where No1=Main.No1) is Null,0,(Select Sum(ml) From juan Where No1=Main.No1)) As ml
From Main
where (Select Sum(ml) From juan Where No1=Main.No1)>0
and (Select Sum(ml) From juan Where No1=Main.No1)<500
#8
我也没太看出哪里有不对的地方。 你试将SUM(juan.ml) AS ml 后的AS ml 的ml 换个名试试。
#9
up