我有一个查询
select count(*)
from purchases
where START_TIME>=TO_DATE('10-NOV-2017 00:00','DD-MON-YY HH24:MI') AND START_TIME<TO_DATE('10-NOV-2017 01:00','DD-MON-YY HH24:MI') and
CLIENT_ID in (1,54);
并且通过使用这个我收集统计数据一个小时。但在过去的7天里,我每天都需要统计数据。
我的意思是,从上面的查询中我收集的是10-NOV-2017 00:00
和10-NOV-2017 01:00
,同样我需要收集09-NOV-2017 00:00
到09-NOV-2017 01:00
等等过去7天。
它应该打印像
Date | Count
+-------------+-------+
10-NOV-2017 | 100
09-NOV-2017 | 110
可以实现吗?
答案 0 :(得分:1)
我会使用像
这样的东西with
dates as (select trunc(sysdate) - rownum + 1 d# from dual connect by level <= 7)
select
d.d#,
sum(case when p.start_time is not null then 1 else 0 end)
from
dates d,
purchases p
where
p.client_id (+) in (1, 54) and
p.start_time (+) between d.d# and d.d# + 1/24
group by
d#
order by
d#
答案 1 :(得分:1)
这适用于您的情况:
SELECT TRUNC (p.start_time), COUNT (*)
FROM purchases p
WHERE START_TIME >= sysdate - INTERVAL '7' DAY
AND START_TIME <= sysdate
AND TO_CHAR (start_time, 'HH24:MI') IN ('00:00', '01:00')
AND CLIENT_ID IN (1, 54)
GROUP BY p.start_time
答案 2 :(得分:0)
这可以满足您的需求吗?
float pauseBeginTime;
float focusTime;
float totalTimeInBackground;
void OnApplicationFocus(bool hasFocus)
{
//Detect return to game
if (hasFocus)
{
Debug.Log("Focused");
focusTime = Time.time;
//Calculate how much waited in the background
totalTimeInBackground = focusTime - pauseBeginTime;
Debug.Log("Stayed in Background for " + totalTimeInBackground);
}
//Detect on-screen keyboard is enabled
else
{
setExitTime();
}
}
void OnApplicationPause(bool pause)
{
//Detect Home button on Android
if (pause)
{
setExitTime();
}
}
void setExitTime()
{
Debug.Log("Paused");
pauseBeginTime = Time.time;
}
答案 3 :(得分:0)
试试这个
SELECT to_char(START_TIME,'DD-MON-YY') date,
count(*) count
FROM
purchases
WHERE
START_TIME >=TO_DATE('10-NOV-2017 00:01','DD-MON-YY HH24:MI') -7
AND START_TIME <TO_DATE('10-NOV-2017 00:02','DD-MON-YY HH24:MI')
AND CLIENT_ID IN (1,54)
group by to_char(START_TIME,'DD-MON-YY') ;