㈠ sql 根据时间段分组统计数据
把小时、分钟分别定义变量,循环变化。
㈡ sql语句怎样按15分钟分组统计
你的意思是每隔15分钟就自己统计数据吗?
㈢ SQL 拆分时间并分组
--假设你的投诉时间字段是date类型
--统计18年累计到当月的投诉量
select
投诉产品,
sum(case when to_char(投诉时间,'yyyymm')='201801' then 1 else 0 end) "一月",
sum(case when to_char(投诉时间,'yyyymm')>='201801' and to_char(投诉时间,'yyyymm')<='201802' then 1 else 0 end) "二月",
sum(case when to_char(投诉时间,'yyyymm')>='201801' and to_char(投诉时间,'yyyymm')<='201803' then 1 else 0 end) "三月",
sum(case when to_char(投诉时间,'yyyymm')>='201801' and to_char(投诉时间,'yyyymm')<='201804' then 1 else 0 end) "四月",
sum(case when to_char(投诉时间,'yyyymm')>='201801' and to_char(投诉时间,'yyyymm')<='201805' then 1 else 0 end) "五月",
sum(case when to_char(投诉时间,'yyyymm')>='201801' and to_char(投诉时间,'yyyymm')<='201806' then 1 else 0 end) "六月",
sum(case when to_char(投诉时间,'yyyymm')>='201801' and to_char(投诉时间,'yyyymm')<='201807' then 1 else 0 end) "七月",
sum(case when to_char(投诉时间,'yyyymm')>='201801' and to_char(投诉时间,'yyyymm')<='201808' then 1 else 0 end) "八月",
sum(case when to_char(投诉时间,'yyyymm')>='201801' and to_char(投诉时间,'yyyymm')<='201809' then 1 else 0 end) "九月",
sum(case when to_char(投诉时间,'yyyymm')>='201801' and to_char(投诉时间,'yyyymm')<='201810' then 1 else 0 end) "十月",
sum(case when to_char(投诉时间,'yyyymm')>='201801' and to_char(投诉时间,'yyyymm')<='201811' then 1 else 0 end) "十一月",
sum(case when to_char(投诉时间,'yyyymm')>='201801' and to_char(投诉时间,'yyyymm')<='201812' then 1 else 0 end) "十二月"
from 投诉表
group by 投诉产品;
--统计每月投诉量
select
投诉产品,
sum(case when to_char(投诉时间,'yyyymm')='201801' then 1 else 0 end) "一月",
sum(case when to_char(投诉时间,'yyyymm')='201802' then 1 else 0 end) "二月",
sum(case when to_char(投诉时间,'yyyymm')='201803' then 1 else 0 end) "三月",
sum(case when to_char(投诉时间,'yyyymm')='201804' then 1 else 0 end) "四月",
sum(case when to_char(投诉时间,'yyyymm')='201805' then 1 else 0 end) "五月",
sum(case when to_char(投诉时间,'yyyymm')='201806' then 1 else 0 end) "六月",
sum(case when to_char(投诉时间,'yyyymm')='201807' then 1 else 0 end) "七月",
sum(case when to_char(投诉时间,'yyyymm')='201808' then 1 else 0 end) "八月",
sum(case when to_char(投诉时间,'yyyymm')='201809' then 1 else 0 end) "九月",
sum(case when to_char(投诉时间,'yyyymm')='201810' then 1 else 0 end) "十月",
sum(case when to_char(投诉时间,'yyyymm')='201811' then 1 else 0 end) "十一月",
sum(case when to_char(投诉时间,'yyyymm')='201812' then 1 else 0 end) "十二月"
from 投诉表
group by 投诉产品;
㈣ sql 指定时间段内分组计算
应该是五个字段吧?
select a,sum(b) as b ,sum(c) as c,sum(d) as d
from table1
where e between '2011-1-1' and '2011-1-3'
group by a
改成这样就可以了
select a,sum(b) as b ,sum(c) as c
from table1
where d between '2011-1-1' and '2011-1-3'
group by a
㈤ SQL如何查询一张表的所有字段并按其中一个字段进行分组
1、创建测试表,
create table test_group_cols(id number, value varchar2(20), remark varchar2(20));
㈥ 求SQL大神给写一个按时间分段的SQL
你这个我觉得类似于,按月分组,按周 按年对数据进行分组,你应该使用系统函数对数据的日期先进性编辑,然后再group by
按月对数据分组的方法
看一下这个是否符合您的要求,如有疑问,及时沟通!
㈦ sql 时间段分组统计查询
有点点麻烦,需要先构建一个关于时间段的虚表
先找到你订单的最早的时间,然后找一个行数足够多的表
假设你的表名叫s,也就是你罗列出数据这个表
withtas
(selectrow_number()over(orderbyid)-1rnfromsheet2)--sheet2替换成你行数足够多的表,还有orderbyid里的id你随便替换你表里的一个字段
selectdateadd(hour,10+24*t.rn,cast('2013/3/1'asdatetime))begin_time,--2013/3/1换成你表里的最小时间
dateadd(hour,10+24*(t.rn+1),cast('2013/3/1'asdatetime))end_time,
count(*)订单数量
fromt,s--这个s替换成你自己的表名
wherecast(s.时间)>=dateadd(hour,10+24*t.rn,cast('2013/3/1'asdatetime))
andcast(s.时间)<dateadd(hour,10+24*(t.rn+1),cast('2013/3/1'asdatetime))
㈧ SQL按时间分组查询
select MONTH(B),sum(A) FROM tt GROUP BY MONTH(B)
㈨ 各位大神请问下,最近24小时,按照分钟来分组的的sql,Oralce中。
--1,字段为时间类型
selectto_char(dtcolumn,'mi')dt,count(*)cnt
fromtable
groupbyto_char(dtcolumn,'mi')
--2,字段为字符类型
selectto_char(to_date(dtcolumn,'yyyymmddhh24miss'),'mi')dt,count(*)cnt
fromtable
groupbyto_char(to_date(dtcolumn,'yyyymmddhh24miss'),'mi')
㈩ MYSQL按分钟分组统计
group by substring(date_time,18,20)/2
大概就是这个思路 你好好看看吧