A small example of grouping and summation in oracle
Cold weather in April 9, 2015
Table gw_log is designed as follows:
Name Type Nullable Default Comments ------------ ----------- -------- ------- ---------- ID VARCHAR2 (50) Message id SERVICE_ID VARCHAR2 (20) Y service ID REQ_TIME date y request time INVOKE_TIME date y call time status char (1) Y '0' 0: failed, 1: Successful RESP_TIME date y response time USER_NAME VARCHAR2 (20) Y username SERVICE_TIME date y call service end time DESCN VARCHAR2 (256) Y description
Count the total number of records that pass the verification and fail the verification on a daily basis:
Successful SQL statement:
select req_time, sum(decode(status, '0', 1, 0)) fail, sum(decode(status, '1', 1, 0)) success from gw_log group by req_time;
The execution result is as follows:
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCgk8L2Jsb2NrcXVvdGU + DQo8L2Jsb2NrcXVvdGU + DQo8aDYgaWQ9 "failed SQL statement"> Failed SQL statement:
select g.req_time, g.success, g.fail from (select a.req_time, count(*) success from gw_log a where 1 = 1 and a.status = 1 group by req_time union all select b.req_time, count(*) fail from gw_log b where 1 = 1 and b.status = 0 group by b.req_time) g
The error message is:
The error cannot be found. If you know it, please point it out to me. Thank you !!!