當前位置:首頁 » 編程語言 » sql欄位按分鍾分組
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql欄位按分鍾分組

發布時間: 2022-08-22 05:15:45

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
大概就是這個思路 你好好看看吧