日期:2014-05-17 浏览次数:20991 次
select (select count(account_id) from
(select account_id
from tab
where substr(visit_time,0,10) = '2012-02-15'
group by account_id
having count(account_id)=1)) o_num,
(select count(0) from tab where substr(visit_time,0,10) = '2012-02-15') t_num
from dual
------解决方案--------------------
select sum(decode(rcnt,1,1,0)),
sum(rcnt)
from(select account_id,
max(rn) rcnt
from(select account_id,
row_number()over(partition by account_id order by id ) rn
from tab
where to_char(visit_time,'YYYY-MM-DD')='2012-02-15')
group by account_id)
------解决方案--------------------
select (select count(account_id) from
(select account_id from tab
where substr(visit_time,0,10)='2012-02-15'
group by account_id
having count(account_id)=1)) o_num,
(select count(0) from tab where substr(visit_time,0,10)='2012-02-15') t_num
from dual
------解决方案--------------------
SELECT sum(CASE WHEN num=1 THEN 1 ELSE 0 END) Login_Once_Count,sum(num) Login_All_Count
FROM
(
SELECT account_id,count(account_id) num FROM tab
WHERE trunc(visit_time)=to_date('15-FEB-12','DD-MON-RR')
GROUP BY account_id
);
------解决方案--------------------
Plan hash value: 3708590803
------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 3 (34)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
| 2 | VIEW | | 1 | 13 | 3 (34)| 00:00:01 |
| 3 | HASH GROUP BY | | 1 | 17 | 3 (34)| 00:00:01 |
|* 4 | TABLE ACCESS FULL| tab | 1 | 17 | 2 (0)| 00:00:01 |
------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter(TRUNC(INTERNAL_FUNCTION("CREATED_AT"))=TO_DATE('17-FEB-12','DD-MON-RR'))
Unable to gather statistics please unsure user has correct access.
The statistic feature requires that the user is granted select on v_$sesstat, v_$statname and v_$session.
------解决方案--------------------