2 回答
TA贡献1775条经验 获得超11个赞
SELECT 11 as conment FROM tableName tb
WHERE tb.dataDate
BETWEEN (
SELECT date_add(DATE_FORMAT(date_add(now(),interval -5 day),'%Y-%m-%d %T'),interval -15 minute))
AND
(SELECT date_add(DATE_FORMAT(date_add(now(),interval -5 day),'%Y-%m-%d %T'),interval +15 minute))
UNION
SELECT 11 as conment FROM tableName tb
WHERE tb.dataDate
BETWEEN (
SELECT date_add(DATE_FORMAT(date_add(now(),interval -4 day),'%Y-%m-%d %T'),interval -15 minute))
AND
(SELECT date_add(DATE_FORMAT(date_add(now(),interval -4 day),'%Y-%m-%d %T'),interval +15 minute))
UNION
SELECT 11 as conment FROM tableName tb
WHERE tb.dataDate
BETWEEN (
SELECT date_add(DATE_FORMAT(date_add(now(),interval -3 day),'%Y-%m-%d %T'),interval -15 minute))
AND
(SELECT date_add(DATE_FORMAT(date_add(now(),interval -3 day),'%Y-%m-%d %T'),interval +15 minute))
UNION
SELECT 11 as conment FROM tableName tb
WHERE tb.dataDate
BETWEEN (
SELECT date_add(DATE_FORMAT(date_add(now(),interval -2 day),'%Y-%m-%d %T'),interval -15 minute))
AND
(SELECT date_add(DATE_FORMAT(date_add(now(),interval -2 day),'%Y-%m-%d %T'),interval +15 minute))
UNION
SELECT 11 as conment FROM tableName tb
WHERE tb.dataDate
BETWEEN (
SELECT date_add(DATE_FORMAT(date_add(now(),interval -1 day),'%Y-%m-%d %T'),interval -15 minute))
AND
(SELECT date_add(DATE_FORMAT(date_add(now(),interval -1 day),'%Y-%m-%d %T'),interval +15 minute))
TA贡献1796条经验 获得超7个赞
不用,一条就可以了。
select 日期,avg(统计的数值) from 表名 where 日期>sysdate-to_number(sysdate-日期) - 15/(60*24) and 日期<sysdate-to_number(sysdate-日期)+ 15/(60*24) and 日期> sysdate-5
group by(turnc(日期))
oracle是这么写的,你结合一下mysql的语法稍微改一下就行
我在oracle测试ok
添加回答
举报