A small example of grouping and summation in oracle

Source: Internet
Author: User

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 !!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.