SQL Nested Query Summary _ database other

Source: Internet
Author: User
It's been a while, at the beginning.
The difficulty is mainly in programming languages, arrays, logic, algorithms,...
After all this has come, the difficulty has risen to the database design.
and data logic.
An excellent system that integrates excellent programs and excellent database design.
This should be done with sufficient experience.
This is a nested query that I wrote with a combination of Uinon.
Put five aspects of the report into a temporary table, and then from the temporary tables, will be the data to query out.
Copy Code code 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 as
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 as
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 as
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 as
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 to everyone.

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.