SQL nested query Summary

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 query the data in the temporary table.
Copy codeThe Code is as follows:
$ 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.

Related Article

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.