Statistics on multiple fields in a table in Oracle (multiple count)

Source: Internet
Author: User

Requirement: Count the total number of tickets in the WAIT_ORDER table, the total number of unprocessed tickets, the total number of completed tickets, and the total number of incomplete tickets.


Table Structure: For the convenience of the example, the WAIT_ORDER table has only two fields: ID and STATUS. The STATUS indicates the ticket STATUS. 1 indicates not processed, 2 indicates completed, and 3 indicates the total number of incomplete tasks.

SQL:

  1. SELECT
  2. COUNT(B. ID)ASTotal number of tickets,
  3. COUNT(CASE
  4. WHENB. statusIN('1')THEN
  5. 'Un _ deal'
  6. END) Total number of unprocessed tickets,
  7. COUNT(CASE
  8. WHENB. statusIN('2')THEN
  9. 'Had _ complete'
  10. END) Total number of completed tickets,
  11. COUNT(CASE
  12. WHENB. status ='3' THEN
  13. 'Un _ complete'
  14. END) Total number of unfinished tickets
  15.  FROMWAIT_ORDER B

Result:

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.