To implement conditional statistics in the count () function, use the SUM function to replace

Source: Internet
Author: User

To implement conditional statistics in the count () function, use the SUM function to replace the count () function and use the SUM function to implement conditional statistics, you can use the case when statement or Decode function to convert the data to 0 or 1, as shown in the following example:

SELECT s. user_id, SUM (case (m. is_success) when 1 then 1 else 0 end), SUM (case when m. read_time is null then 0 else 1 end), COUNT (*) from doc_score s, mail_send_log m where s. user_id in (6, 7, 8, 9) and s. status = 1 and m.doc _ id = s.doc _ id group by s. user_id;

 


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.