求一sql语句

xuxiaomei2707 2014-04-11 08:59:34
select dtSTime,dtETime,iCount from tLP 查询一个表,表中数据是这样的:
dtSTime dtETime iCount
2014-04-10 2014-04-30 6
2014-05-08 2014-05-14 5
2014-04-10 2014-04-30 1
2014-05-08 2014-05-14 3

第一条和第三条的数据开始时间和结束时间是相同的,数量不同,我想查询的结果是:
dtSTime dtETime iCount
2014-04-10 2014-04-30 7
2014-05-08 2014-05-14 8

相同时间的数量相加




...全文
192 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
泡芙小姐1228 2014-04-16
  • 打赏
  • 举报
回复
楼上的方法能够实现。学习了 think you
Mr_Nice 2014-04-11
  • 打赏
  • 举报
回复

SELECT  dtSTime, dtETime,SUM(iCount) AS icount,(case when tLP.dDoPrice=0 then '小' else '大' end) as cStyle
FROM tLP
GROUP BY  dtSTime, dtETime,case when tLP.dDoPrice=0 then '小' else '大' end
向东流 2014-04-11
  • 打赏
  • 举报
回复
select dtstime,dtetime,sum(icount) as icount,
case when dDoPrice=0 then '小' else '大' end as cStyle from tLP
group by dtstime,dtetime,case when dDoPrice=0 then '小' else '大' end
xuxiaomei2707 2014-04-11
  • 打赏
  • 举报
回复
另外补充一下 表中还有一列价格dDoPrice dtSTime dtETime iCount dDoPrice 2014-04-10 2014-04-30 6 500 2014-05-08 2014-05-14 5 20 2014-04-10 2014-04-30 1 300 2014-05-08 2014-05-14 3 400 2014-05-08 2014-05-14 3 0 要判断 (case when tLP.dDoPrice=0 then '小' else '大' end) as cStyle 得到的数据是 dtSTime dtETime iCount cStyle 2014-04-10 2014-04-30 7 大 2014-05-08 2014-05-14 8 大 2014-05-08 2014-05-14 3 小
sedshy 2014-04-11
  • 打赏
  • 举报
回复

select dtSTime, dtETime, sum(iCount) as iCount from tLP
group by dtSTime, dtETime

6,128

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 新技术前沿
社区管理员
  • 新技术前沿社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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