我有一个表,数据量比较大,我想统计它在哪一个时间段数据量是最大的(时段为2小时,如:2010.9.08 14:00—16:00)!
解决方案 »
- 求SQL
- Oracle的(+)的左右连接的方式被摒弃了么?
- oracle 含数字的字符串的排序问题
- 大公司大企业的程序员们请进?
- 用java操作oracle,涉及select 与update,执行一段时间后,程序像停止工作似的,但不异常,过很长时间又开始,但慢的要死
- jdbc调用带游标返回的存储过程,返回为空怎么判断(SQL当中带sum())
- 急急急???在RH9下安装ORACLE8I数据库
- 关于整表的^^请教!!!!
- 在asp中如何调用oracle 包中的储存过程,使用的是adodb.connection方法连接数据库
- 为什么我装完Oracle 9i!启动不了Enterprise Manager Console?
- 高手给看看。。 简单问题。。
- 一道sql面试题,求解
select t1.rn,count(*) from yourtable a,t1 where a.date字段 between t1.rn and t1.rn+1/12-1/24/60/60
group by t1.rn
Connected as scott
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
7369 SMITH CLERK 1000 1980-12-17 800.10 20
7499 ALLEN SALESMAN 7698 1981-2-20 1600.00 300.00 30
7521 WARD SALESMAN 7698 1981-2-22 1250.00 500.00 30
7566 JONES MANAGER 7839 1981-4-2 2975.00 20
7654 MARTIN SALESMAN 7698 1981-9-28 1250.00 1400.00 30
7698 BLAKE MANAGER 7839 1981-5-1 2850.00 30
7782 CLARK MANAGER 7839 1981-6-9 2450.00 10
7788 SCOTT ANALYST 7566 1987-4-19 3000.00 20
7839 KING PRESIDENT 1981-11-17 5000.00 10
7844 TURNER SALESMAN 7698 1981-9-8 1500.00 0.00 30
7876 ADAMS CLERK 7788 1987-5-23 1100.00 20
7900 JAMES CLERK 7698 1981-12-3 950.00 30
7902 FORD ANALYST 7566 1981-12-3 3000.00 20
7934 MILLER CLERK 7782 1982-1-23 1300.00 10
14 rows selected
SQL> with t1 as (select rownum-1+(select trunc(min(hiredate)) from emp) rn from dual connect by rownum/12<=(select trunc(max(hiredate)+1)-trunc(min(hiredate)) from emp))
2 select t1.rn,count(*) from emp a,t1 where a.hiredate between t1.rn and t1.rn+1/12-1/24/60/60
3 group by t1.rn
4 ;
RN COUNT(*)
----------- ----------
1980-12-17 1
1981-2-20 1
1981-2-22 1
1981-4-2 1
1981-5-1 1
1981-6-9 1
1981-9-8 1
1981-9-28 1
1981-11-17 1
1981-12-3 2
1982-1-23 1
1987-4-19 1
1987-5-23 1
13 rows selected
SQL>
with t1 as (select (rownum-1)/12+(select trunc(min(hiredate)) from emp) rn from dual connect by rownum/12<=(select trunc(max(hiredate)+1)-trunc(min(hiredate)) from emp))
select t1.rn,count(*) from emp a,t1 where a.hiredate between t1.rn and t1.rn+1/12-1/24/60/60
group by t1.rn
with t as(
select 100+level rid,'00000000'||(Mod(LEVEL,4)) client_version_code, LEVEL login_count,
SYSDATE+LEVEL*24/3600 login_time from dual
connect by level<=30)
SELECT
CASE WHEN 0<=tm and tm<2 THEN '0-2'
WHEN 2<=tm AND tm<4 THEN '2-4'
WHEN 4<=tm AND tm<6 THEN '4-6'
WHEN 6<=tm AND tm<8 THEN '6-8'
WHEN 8<=tm AND tm<10 THEN '8-10'
WHEN 10<=tm AND tm<12 THEN '10-12'
WHEN 12<=tm AND tm<14 THEN '12-14'
WHEN 14<=tm AND tm<16 THEN '14-16'
WHEN 16<=tm AND tm<18 THEN '16-18'
WHEN 18<=tm AND tm<20 THEN '18-20'
WHEN 20<=tm AND tm<22 THEN '20-22'
ELSE '22-24' END 时间 ,
版本一,版本二,版本三,版本四,总计
FROM (
SELECT
To_Number(To_Char(login_time,'hh24')) tm,
Sum(decode(client_version_code,'000000000',login_count)) 版本一,
Sum(decode(client_version_code,'000000001',login_count)) 版本二,
Sum(decode(client_version_code,'000000002',login_count)) 版本三,
Sum(decode(client_version_code,'000000003',login_count)) 版本四,
Sum(login_count) 总计
from t
GROUP BY To_Char(login_time,'hh24')
);
SELECT COUNT(1),TO_CHAR(dateColumn,'yyyy-mm-dd HH24')
FROM table
GROUP BY TO_CHAR(dateColumn,'yyyy-mm-dd HH24')
ORDER BY 1 DESC
SELECT decode(mod(to_char(hiredate,'hh24'),2),1,to_char(hiredate-1/24,'yyyy-mm-dd hh24'),to_char(hiredate,'yyyy-mm-dd hh24')),count(*)
FROM emp
GROUP BY decode(mod(to_char(hiredate,'hh24'),2),1,to_char(hiredate-1/24,'yyyy-mm-dd hh24'),to_char(hiredate,'yyyy-mm-dd hh24'));