如何计算一个字段的合计值?SQL的语法应怎样写才正确?
23 个解决方案
#1
select (f1+f2+f3) as ff from table
rs("ff")
rs("ff")
#2
错了,会错了楼主的意思。对不起。
#3
select sum(f1) as totalf1 from tablename
rs("totalf1")
rs("totalf1")
#4
支持BrightEye(问个不休)
#5
SELECT * sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY COUNTRY
我这样写老是提示语法错误?为什么?
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY COUNTRY
我这样写老是提示语法错误?为什么?
#6
SELECT SUM(CAST(fl AS float)) AS totalf1 from tablename
response.write rs("totalf1")
最好是先转换成为:int 或者 float 类型
response.write rs("totalf1")
最好是先转换成为:int 或者 float 类型
#7
首先没逗号,其次*和SUM根本不能同时写!
#8
试试这样写:
SELECT sum(BILL.AMOUNT) as total
FROM BILL
inner join emp
on BILL.CODE = EMP.CODE
ORDER BY bill.COUNTRY
这样应该可以了!
SELECT sum(BILL.AMOUNT) as total
FROM BILL
inner join emp
on BILL.CODE = EMP.CODE
ORDER BY bill.COUNTRY
这样应该可以了!
#9
那应该怎么写啊?
#10
我按你的代码写后,提示“参数不足,期待是1”是什么原因?
#11
下面是個統計每個學生總會的例子﹐希望對你有用
stu_no : 學號﹔
store : 成績﹔
AdoCon : 建立的數據通道
<%
Set AdoRst=Server.CreateObject("ADODB.RECORDER")
SQLStr="Select Sum(store) as Stores,stu_no From study Group "&_
" By stu_no "
AdoRst.Open SQlStr,AdoCon,3
For i=1 To AodRst.RecordCount
StrA=AdoRst("stu_no")
StrB=AdoRst("Stores")
StrAB="學號:"& StrA &"總分:"& StrB &Vbcrlf
Response.Write StrAB
Next %>
這里不要用姓名是因為有可能有同名的學生。
stu_no : 學號﹔
store : 成績﹔
AdoCon : 建立的數據通道
<%
Set AdoRst=Server.CreateObject("ADODB.RECORDER")
SQLStr="Select Sum(store) as Stores,stu_no From study Group "&_
" By stu_no "
AdoRst.Open SQlStr,AdoCon,3
For i=1 To AodRst.RecordCount
StrA=AdoRst("stu_no")
StrB=AdoRst("Stores")
StrAB="學號:"& StrA &"總分:"& StrB &Vbcrlf
Response.Write StrAB
Next %>
這里不要用姓名是因為有可能有同名的學生。
#12
SELECT sum(BILL.AMOUNT) as total
FROM BILL,EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY emp.COUNTRY 或者order by bill.country看你的字段是在哪个表里面.
FROM BILL,EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY emp.COUNTRY 或者order by bill.country看你的字段是在哪个表里面.
#13
楼主是查询两个表
1. "*"不能与sum()同时用
2. 去掉 Order By
3. 转换字段类型(原先类型为数字的可不转换)
原:
SELECT * sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY COUNTRY
改后:
SELECT sum(Cast(BILL.AMOUNT As float)) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
1. "*"不能与sum()同时用
2. 去掉 Order By
3. 转换字段类型(原先类型为数字的可不转换)
原:
SELECT * sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY COUNTRY
改后:
SELECT sum(Cast(BILL.AMOUNT As float)) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
#14
SELECT xxx, xxx, xxx, sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY BILL.COUNTRY
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY BILL.COUNTRY
#15
谢谢各位大侠的帮助!
我用下面的代码可以显示合计项,但不能显示其他字段,是何道理?
SELECT sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
我加入字段
SELECT bill.date, bill.code, bill.tele, sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
提示试图执行的查询中不包含作为合计函数的一部分的特定表达式` date`
我用下面的代码可以显示合计项,但不能显示其他字段,是何道理?
SELECT sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
我加入字段
SELECT bill.date, bill.code, bill.tele, sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
提示试图执行的查询中不包含作为合计函数的一部分的特定表达式` date`
#16
date是不是关键字?
你换个名字看看。要不就你没有这个字段
你换个名字看看。要不就你没有这个字段
#17
select sum(f) as total from tablename
response.write rs("total")
response.write rs("total")
#18
select xxx as xxx from xxxx
#19
在聚合查询中,只能使用聚合函数输出字段..
如果希望输出除聚合函数之外的标量值,可以使用相关子查询取代.
如果希望输出除聚合函数之外的标量值,可以使用相关子查询取代.
#20
SELECT bill.date, bill.code, bill.tele, sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
group by bill.date, bill.code, bill.tele
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
group by bill.date, bill.code, bill.tele
#21
我照楼上的这样写,如BILL.DATE,BILL.CODE,BILL.TELE有同样的多笔记录
AMOUNT就不能合计了,怎么办?
AMOUNT就不能合计了,怎么办?
#22
SELECT a.date,a.code,a.tele,d.total
FROM BILL as a ,
(select sum(b.amount),b.code
from bill as b,emp as c
where b.code=c.code group by b.code ) as d
where a.code=d.code
試試看,記得把分行的空格去掉(分行主要是為了看得更清楚)
FROM BILL as a ,
(select sum(b.amount),b.code
from bill as b,emp as c
where b.code=c.code group by b.code ) as d
where a.code=d.code
試試看,記得把分行的空格去掉(分行主要是為了看得更清楚)
#23
各位大俠請關注:
怎樣對 file 類型賦初值?(Tracy2002)
謝謝!
怎樣對 file 類型賦初值?(Tracy2002)
謝謝!
#1
select (f1+f2+f3) as ff from table
rs("ff")
rs("ff")
#2
错了,会错了楼主的意思。对不起。
#3
select sum(f1) as totalf1 from tablename
rs("totalf1")
rs("totalf1")
#4
支持BrightEye(问个不休)
#5
SELECT * sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY COUNTRY
我这样写老是提示语法错误?为什么?
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY COUNTRY
我这样写老是提示语法错误?为什么?
#6
SELECT SUM(CAST(fl AS float)) AS totalf1 from tablename
response.write rs("totalf1")
最好是先转换成为:int 或者 float 类型
response.write rs("totalf1")
最好是先转换成为:int 或者 float 类型
#7
首先没逗号,其次*和SUM根本不能同时写!
#8
试试这样写:
SELECT sum(BILL.AMOUNT) as total
FROM BILL
inner join emp
on BILL.CODE = EMP.CODE
ORDER BY bill.COUNTRY
这样应该可以了!
SELECT sum(BILL.AMOUNT) as total
FROM BILL
inner join emp
on BILL.CODE = EMP.CODE
ORDER BY bill.COUNTRY
这样应该可以了!
#9
那应该怎么写啊?
#10
我按你的代码写后,提示“参数不足,期待是1”是什么原因?
#11
下面是個統計每個學生總會的例子﹐希望對你有用
stu_no : 學號﹔
store : 成績﹔
AdoCon : 建立的數據通道
<%
Set AdoRst=Server.CreateObject("ADODB.RECORDER")
SQLStr="Select Sum(store) as Stores,stu_no From study Group "&_
" By stu_no "
AdoRst.Open SQlStr,AdoCon,3
For i=1 To AodRst.RecordCount
StrA=AdoRst("stu_no")
StrB=AdoRst("Stores")
StrAB="學號:"& StrA &"總分:"& StrB &Vbcrlf
Response.Write StrAB
Next %>
這里不要用姓名是因為有可能有同名的學生。
stu_no : 學號﹔
store : 成績﹔
AdoCon : 建立的數據通道
<%
Set AdoRst=Server.CreateObject("ADODB.RECORDER")
SQLStr="Select Sum(store) as Stores,stu_no From study Group "&_
" By stu_no "
AdoRst.Open SQlStr,AdoCon,3
For i=1 To AodRst.RecordCount
StrA=AdoRst("stu_no")
StrB=AdoRst("Stores")
StrAB="學號:"& StrA &"總分:"& StrB &Vbcrlf
Response.Write StrAB
Next %>
這里不要用姓名是因為有可能有同名的學生。
#12
SELECT sum(BILL.AMOUNT) as total
FROM BILL,EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY emp.COUNTRY 或者order by bill.country看你的字段是在哪个表里面.
FROM BILL,EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY emp.COUNTRY 或者order by bill.country看你的字段是在哪个表里面.
#13
楼主是查询两个表
1. "*"不能与sum()同时用
2. 去掉 Order By
3. 转换字段类型(原先类型为数字的可不转换)
原:
SELECT * sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY COUNTRY
改后:
SELECT sum(Cast(BILL.AMOUNT As float)) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
1. "*"不能与sum()同时用
2. 去掉 Order By
3. 转换字段类型(原先类型为数字的可不转换)
原:
SELECT * sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY COUNTRY
改后:
SELECT sum(Cast(BILL.AMOUNT As float)) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
#14
SELECT xxx, xxx, xxx, sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY BILL.COUNTRY
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
ORDER BY BILL.COUNTRY
#15
谢谢各位大侠的帮助!
我用下面的代码可以显示合计项,但不能显示其他字段,是何道理?
SELECT sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
我加入字段
SELECT bill.date, bill.code, bill.tele, sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
提示试图执行的查询中不包含作为合计函数的一部分的特定表达式` date`
我用下面的代码可以显示合计项,但不能显示其他字段,是何道理?
SELECT sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
我加入字段
SELECT bill.date, bill.code, bill.tele, sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
提示试图执行的查询中不包含作为合计函数的一部分的特定表达式` date`
#16
date是不是关键字?
你换个名字看看。要不就你没有这个字段
你换个名字看看。要不就你没有这个字段
#17
select sum(f) as total from tablename
response.write rs("total")
response.write rs("total")
#18
select xxx as xxx from xxxx
#19
在聚合查询中,只能使用聚合函数输出字段..
如果希望输出除聚合函数之外的标量值,可以使用相关子查询取代.
如果希望输出除聚合函数之外的标量值,可以使用相关子查询取代.
#20
SELECT bill.date, bill.code, bill.tele, sum(BILL.AMOUNT) as total
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
group by bill.date, bill.code, bill.tele
FROM BILL, EMP
WHERE BILL.CODE = EMP.CODE
group by bill.date, bill.code, bill.tele
#21
我照楼上的这样写,如BILL.DATE,BILL.CODE,BILL.TELE有同样的多笔记录
AMOUNT就不能合计了,怎么办?
AMOUNT就不能合计了,怎么办?
#22
SELECT a.date,a.code,a.tele,d.total
FROM BILL as a ,
(select sum(b.amount),b.code
from bill as b,emp as c
where b.code=c.code group by b.code ) as d
where a.code=d.code
試試看,記得把分行的空格去掉(分行主要是為了看得更清楚)
FROM BILL as a ,
(select sum(b.amount),b.code
from bill as b,emp as c
where b.code=c.code group by b.code ) as d
where a.code=d.code
試試看,記得把分行的空格去掉(分行主要是為了看得更清楚)
#23
各位大俠請關注:
怎樣對 file 類型賦初值?(Tracy2002)
謝謝!
怎樣對 file 類型賦初值?(Tracy2002)
謝謝!