sql语句汇总问题,请大侠指教!
收银员1 收款金额
收银员2 收款金额
收银员3 收款金额
总金额 (收款员1+收银员2 + 收款员3 )
if Request( "shyy ") = "全部 " then
sql = "SELECT username, sum(c.amount) as sshje FROM T_pos_bill_header a,T_user b,T_pos_bill_payment c where a.casherid=b.userid AND a.pbseqid=c.pbseqid and TO_char(billdate, 'YYYY-MM-DD ') between ' "&date1& " ' and ' "&date2& " ' group by username "
end if
这最后的汇总总金额的语句怎么写,要输出在界面上
------解决方案--------------------放在 SQL 里:
SELECT username, sum(c.amount) as sshje FROM T_pos_bill_header a,T_user b,T_pos_bill_payment c where a.casherid=b.userid AND a.pbseqid=c.pbseqid and TO_char(billdate, 'YYYY-MM-DD ') between ' "&date1& " ' and ' "&date2& " ' group by username
union
SELECT '总金额 ' as username, sum(c.amount) as sshje FROM T_pos_bill_header a,T_user b,T_pos_bill_payment c where a.casherid=b.userid AND a.pbseqid=c.pbseqid and TO_char(billdate, 'YYYY-MM-DD ') between ' "&date1& " ' and ' "&date2& " '
上面这个就是利用了 union 来直接用一个记录集把各人金额及总金额拿出来
还有用 asp 的运算来拿就简单了:
比如 rs 代表你拿到的各营业员的金额记录集
那么
TotalAmount = 0
do while not rs.eof
TotalAmount = TotalAmount + rs( "sshje ")
rs.movenext
loop
response.write "总金额是 "& TotalAmount
这样就行了,哈哈~~~
专治便秘~~~