sql查询当天时间段的数据,如何将6条查询合并成1条
sql查询当天时间段的数据,怎么将6条查询合并成1条
String hql1 = "select count(*) from Tclient where dcodeId =: dcodeId and calltime between '"+time+" 00:00' and '"+time+" 04:00'"
String hql2 = "select count(*) from Tclient where dcodeId = '"+count.getDcodeId()+"' and calltime between '"+time+" 04:00' and '"+time+" 08:00'";
String hql3 = "select count(*) from Tclient where dcodeId = '"+count.getDcodeId()+"' and calltime between '"+time+" 08:00' and '"+time+" 12:00'";
String hql4 = "select count(*) from Tclient where dcodeId = '"+count.getDcodeId()+"' and calltime between '"+time+" 12:00' and '"+time+" 16:00'";
String hql5 = "select count(*) from Tclient where dcodeId = '"+count.getDcodeId()+"' and calltime between '"+time+" 16:00' and '"+time+" 20:00'";
String hql6 = "select count(*) from Tclient where dcodeId = '"+count.getDcodeId()+"' and calltime between '"+time+" 20:00' and '"+time+" 24:00'";
------解决思路----------------------
你自己转成程序字符串。
------解决思路----------------------
用union all 连接可以把结果集拼接成一个。
------解决思路----------------------
不是SQL Server请转到对应的论坛去。
String hql1 = "select count(*) from Tclient where dcodeId =: dcodeId and calltime between '"+time+" 00:00' and '"+time+" 04:00'"
String hql2 = "select count(*) from Tclient where dcodeId = '"+count.getDcodeId()+"' and calltime between '"+time+" 04:00' and '"+time+" 08:00'";
String hql3 = "select count(*) from Tclient where dcodeId = '"+count.getDcodeId()+"' and calltime between '"+time+" 08:00' and '"+time+" 12:00'";
String hql4 = "select count(*) from Tclient where dcodeId = '"+count.getDcodeId()+"' and calltime between '"+time+" 12:00' and '"+time+" 16:00'";
String hql5 = "select count(*) from Tclient where dcodeId = '"+count.getDcodeId()+"' and calltime between '"+time+" 16:00' and '"+time+" 20:00'";
String hql6 = "select count(*) from Tclient where dcodeId = '"+count.getDcodeId()+"' and calltime between '"+time+" 20:00' and '"+time+" 24:00'";
------解决思路----------------------
SELECT DATEPART(hour,calltime)/4 AS g,
count(*)
FROM Tclient
WHERE dcodeId = @dcodeId
GROUP BY DATEPART(hour,calltime)/4
你自己转成程序字符串。
------解决思路----------------------
用union all 连接可以把结果集拼接成一个。
------解决思路----------------------
不是SQL Server请转到对应的论坛去。