50分求1句sql查询语句...在线等...解决问题马上给分!!!!

Jorn 2003-12-14 02:07:45
问题是这样的:
我的表中有laidaotime,likaitime,totaltime,userid四个字段,我的sql语句要实现的功能是将userid相同的totaltime相加,而且我只需要laidaotime在firsttime和lasttime两个变量之间的数据!
我写的sql语句是:sql="select sum(totaltime) as ttime,userid,laidao from shijian where laidao between '"&firstdate&"' and '"&lastdate&"'" group by userid ,这个sql语句是错的!!!
...全文
43 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bullion 2003-12-14
  • 打赏
  • 举报
回复
GROUP BY 跟 SELECT SUM(totaltime) as ttime,userid,laidao 结合

如果SELECT里面带更多参数的话,GROUP BY 后要带更多的参数,如:

SELECT SUM(totaltime) as ttime,userid,laidao,aa,bb,cc
from shijian
where laidao between '"&firstdate&"' and '"&lastdate&"'"
GROUP BY userid,laido,aa,bb,cc
bullion 2003-12-14
  • 打赏
  • 举报
回复
SQL:

SELECT SUM(totaltime) as ttime,userid,laidao from shijian
where laidao between '"&firstdate&"' and '"&lastdate&"'"
GROUP BY userid,laido
ivy_ou 2003-12-14
  • 打赏
  • 举报
回复
楼主你想要什么数据呢?
sum(totaltime)和group by是聚合的,不能同时这样取userid,laidao 字断内容
是以什么排序呢?
是取每个人来到的最新来的时间,然后来到的总数?
a_zhe_20 2003-12-14
  • 打赏
  • 举报
回复
sql="select sum(totaltime) as ttime,userid,laidaotime from shijian where laidaotime >#"&firstdate&"# and laidaotime<#"&lastdate&"# group by userid

你的表里没有laidao字段啊。
ivy_ou 2003-12-14
  • 打赏
  • 举报
回复

select sum(totaltime) as ttime ,userid ,laidao from shijian where laidao between '"&firstdate&"' and '"&lastdate&"'" and userid in ( select userid from shijian group by userid)
Jorn 2003-12-14
  • 打赏
  • 举报
回复
guo1wu3shi4(guowushi),谢谢你帮助,但是还是错误,和我那句语句的错误一样
guo1wu3shi4 2003-12-14
  • 打赏
  • 举报
回复
select userid,sum(totaltime) from tablename where laidaotime >firsttime and laidaotime <lasttime group by userid

28,408

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧