sql语句sum()求和 不会写了... ( 积分: 50 )

  • 主题发起人 主题发起人 why_119
  • 开始时间 开始时间
W

why_119

Unregistered / Unconfirmed
GUEST, unregistred user!
select
A.username,A.userid,B.userid,B.djs
from
user A,dj B
where
A.username='" & UserName & "' and B.userid=A.userid


sum(B.djs)求和 咋写呀
 
select
A.username,A.userid,B.userid, sum(B.djs)
from
user A,dj B
where
A.username='" & UserName & "' and B.userid=A.userid
group by A.username,A.userid,B.userid
 
select
A.username,A.userid,B.userid,sum(B.djs)
from
user A,dj B
where
A.username='" & UserName & "' and B.userid=A.userid
group by A.username,A.userid,B.userid
 
不对求不出来.
是不是应该写
group by B.djs
 
你还是用中文教详细描述一下你的目的好了,这样别人才容易帮助你。
 
还是不行呀.
 
select
A.username,A.userid,B.userid,sum(B.djs)
from
user A,dj B
where
A.username='" & UserName & "' and B.userid=A.userid
group by A.username,A.userid,B.userid


就是这个吧
 
应该是对的吧...
你看看你的数据吧,....
 
sql="select A.username,A.userid,B.userid,B.date,sum(B.djs) as t_djs
from user A,dj B
where A.username='" & UserName & "'
and B.userid=A.userid
and FormatDateTime(B.date,2)=Date()
group by A.username,A.userid,B.userid,B.date"
求和没问提了.我加了一个求当日的 就不行了.
B.date的格式为2007-10-28 21:49:35
 
求当日的不能使用FormatDateTime
sql="select A.username,A.userid,B.userid,B.date,sum(B.djs) as t_djs
from user A,dj B
where A.username='" & UserName & "'
and B.userid=A.userid
and Convert(VarChar(10),B.date,120)=Convert(VarChar(10),GetDate(),120)
group by A.username,A.userid,B.userid,B.date"
就OK了啊.前提b.date为日期型
 
sql="select A.username,A.userid,B.userid,B.date,sum(B.djs) as t_djs
from user A,dj B
where A.username='" & UserName & "'
and B.userid=A.userid
and Convert(VarChar(10),B.date,120)=Convert(VarChar(10),GetDate(),120)
group by A.username,A.userid,B.userid,B.date"
 
多人接受答案了。
 

Similar threads

后退
顶部