SQL nested query summary Xiaoxiang blog

Source: Internet
Author: User

It has been around for a while. At the beginning ''''''

The difficulty is mainly in programming languages, arrays, logic, algorithms ,...

After these steps, the difficulties will rise to the database design.

And Data logic.

 

An excellent system will integrate excellent programs and excellent database design.

Enough experience is needed to achieve this.

 

This is a nested query that I wrote combined with uinon.

Put the five reports in a temporary table, and then from the temporary table

The data to be queried.

 

 

$ SQL = "select type, sum (yjsl) as yjsl, sum (yysl) as yysl, sum (jyrs) as jyrs, sum (jycs) as jycs
From (

Select C. MC
Type, count (D. lsh) as yjsl, 0 as yysl, 0 as jyrs, 0 as jycs
From sys_dzxxb as B, sys_jcb as C, sys_dzyjb as d
Where B. BM = C. lsh
And D. dzlsh = B. lsh
Group by C. MC
Union select C. MC
Type, 0 as yjsl, count (E. lsh) as yysl, 0 as jyrs, 0 as jycs
From sys_dzxxb as B, sys_jcb as C, sys_dzyy as E
Where B. BM = C. lsh
And E. dzlsh = B. lsh
Group by C. MC
Union select C. MC
Type, 0 as yjsl, 0 as yysl, count (distinct E. dzlsh) as jyrs, 0 as jycs
From sys_dzxxb as B, sys_jcb as C, sys_ltxxb as E
Where B. BM = C. lsh
And E. dzlsh = B. lsh
Group by C. MC
Union select C. MC
Type, 0 as yjsl, 0 as yysl, 0 as jyrs, count (distinct E. lsh) as jycs
From sys_dzxxb as B, sys_jcb as C, sys_ltxxb as E
Where B. BM = C. lsh
And E. dzlsh = B. lsh
Group by C. MC
) As temptable
Group by type ";

 

 

Share with 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.