Use of case when else statements

Source: Internet
Author: User


/* Total number of patients with high disease in the administrative village of the Production and Marketing institution the number of high-severity patients managed this month (one service per year) the number of high-severity patients managed this month (four follow-up visits per year) high disease experience this month high disease total number of people who examined sugar disease this month new patient construction sugar disease total number of people who established the party number of diabetes management this month number of people who managed diabetes this month standard management Number of people who examined diabetes this month cumulative number of people who examined diabetes www.2cto.com * // the key points of the case when else syntax are described as follows: 1. Start with CASE, END with END 2. WHEN followed by a condition in the branch, THEN is the result 3. ELSE is the default condition, similar to the default switch case in a advanced language program, you can remove 4, END followed by alias */select * from (select jg. jwh. name of as administrative village, count (distinct case when rqfl. id = '34f596b0-03ce-4e51-b6b3-a3167b92ae87 'then grza. count (distinct casewhen rqfl. id = '7553a063-99F8-4DB9-BDAC-D21C8BBDB243 'then grza. personal idend) Cumulative number of patients with as sugar disease, count (distinct casewhen fwxmml. id = '667c2146-BA8C-4937-9ACC-A7D8DB6C2712 'and fwhdjl. registration Time> = to_date ('2017-03-01 ', 'yyyy-mm-dd') and fwhdjl. registration time <= to_date ('2017-03-01 ', 'yyyy-mm-dd') then fwhdjl. personal id end) as high-severity regular management count this month, count (distinct casewhen fwxmml. id = 'ac955b0f-E396-4ED6-998D-3746F91EDB8B 'and fwhdjl. registration Time> = to_date ('2017-03-01 ', 'yyyy-mm-dd') www.2cto.com and fwhdjl. registration time <= to_date ('2017-03-01 ', 'yyyy-mm-dd') then fwhdjl. personal id end) number of standardized management for as diabetes this month, count (distinct case when fwxmml. id = '67f5d7fa-D7C2-4244-B9DB-FC34A8E96C57 'and fwhdjl. registration Time> = to_date ('2017-03-01 ', 'yyyy-mm-dd') and fwhdjl. registration time <= to_date ('2017-03-01 ', 'yyyy-mm-dd') then fwhdjl. personal id end) as hypertension follow-up count (distinct case when fwxmml. id = 'ac955b0f-E396-4ED6-998D-3746F91EDB8B 'and fwhdjl. registration Time> = to_date ('2017-03-01 ', 'yyyy-mm-dd') and fwhdjl. registration time <= to_date ('2017-03-01 ', 'yyyy-mm-dd') then fwhdjl. personal id end) as diabetes follow-up count from personal information gr, institution jg, neighborhood committee jwh, personal project grza, population classification rqfl, service activity record fwhdjl, service project directory fwxmmlwhere gr. current Organization id = jg. resource idAnd gr. neighborhood committee id = jwh. idAnd grza. personal id = gr. idAnd grza. group id = rqfl. idAnd fwhdjl. personal id = gr. idAnd fwhdjl. project id = fwxmml. idgroup by jg. jwh. name) where hypertension follow-up> 4 and diabetes follow-up> 4/* Total number of names and hypertension follow-up persons under the current institution */select count (1) www.2cto.com from (select gr. name, count (1) number of follow-up persons with hypertension from personal information gr, institution jg, service activity record fwhdjl, service project directory fwhdxmml where gr. current Organization id = jg. resource idand fwhdjl. personal id = gr. idand fwhdjl. project id = fwhdxmml. idand fwhdxmml. name = 'hypertension follow-up 'and fwhdjl. registration Time> = to_date ('2017-03-01 ', 'yyyy-mm-dd') and fwhdjl. registration time <= to_date ('2017-03-01 ', 'yyyy-mm-dd') group by gr. name) where hypertension follow-up count> = 4 author Zhangyujie

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.