Count the data of yesterday and today by Unit

Source: Internet
Author: User

Count the data of yesterday and today, and first find out the Unit by unit grouping, and then perform external association with the subquery in the Java code select * from -- Query all the institutions in the organization table (select distinct dc. district_code, dc. id unit_id, dc. unit_name FROM pc_base_unit dc) o left join -- count the data of the day before yesterday (SELECT dc. unit_id, SUM (dc. OUTPATIENT_REGISTER) Outpatient registration, SUM (dc. RECIPEL_DETAIL) Outpatient prescription details, SUM (dc. INHOSPITAL_REGISTER) Hospitalization registration, SUM (dc. INHOSPITAL_DETAIL) Hospital details, SUM (dc. BASEINFO) Basic information of the file FROM pc_data_datacleancollect dc WHERE to_char (dc. CLEAN_TIME, 'yyyy-mm-dd') = to_char (SYSDATE-2, 'yyyy-mm-dd') group by dc. unit_id) a ON o. unit_id =. unit_id left join (-- calculate the data of yesterday's SELECT dc. unit_id, SUM (dc. OUTPATIENT_REGISTER) Outpatient registration, SUM (dc. RECIPEL_DETAIL) Outpatient prescription details, SUM (dc. INHOSPITAL_REGISTER) Hospitalization registration, SUM (dc. INHOSPITAL_DETAIL) Hospital details, SUM (dc. BASEINFO) Basic information of the file FROM pc_data_datacleancollect dc WHERE to_char (dc. CLEAN_TIME, 'yyyy-mm-dd') = to_char (SYSDATE-1, 'yyyy-mm-dd') group by dc. unit_id) B ON o. unit_id = B. unit_id left join (-- calculate the data of today's SELECT dc. unit_id, SUM (dc. OUTPATIENT_REGISTER) Outpatient registration, SUM (dc. RECIPEL_DETAIL) Outpatient prescription details, SUM (dc. INHOSPITAL_REGISTER) Hospitalization registration, SUM (dc. INHOSPITAL_DETAIL) Hospital details, SUM (dc. BASEINFO) Basic information of the file FROM pc_data_datacleancollect dc WHERE to_char (dc. CLEAN_TIME, 'yyyy-mm-dd') = to_char (SYSDATE, 'yyyy-mm-dd') group by dc. unit_id) c ON o. unit_id = c. unit_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.