Home > database >  Consult a SQL, is more complex, all points to one time
Consult a SQL, is more complex, all points to one time

Time:11-07

The following query can merge into a?

 
Select sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880047288048288016288006)
Select sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880045288005)
Select sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880034288033)
Select sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880032288029)
Select sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880012288014288046)
Select sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880010288011)
Select sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880009288013)
Select sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880044)


Data table description
There is A table in the database (A), store the agency, but does not rule, such as:

JGH
-- -- -- -- --
2880047288048288016288006
-- -- -- -- --
2880045288005
-
2880044
-
2880037

And (B) a table to store the data, but the number is rules, such as:

JGH ckye
-- -- -- -- -- -- -- -- --
2880047 1
-- -- -- -- -- -- -- -- --
2880048 1
-- -- -- -- -- -- -- --
2880016 1
-- -- -- -- -- -- -- --
2880006 1
-- -- -- -- -- -- -- --
2880045 1
-- -- -- -- -- -- -- --
2880044 1
-- -- -- -- -- -- -- --
2880005 1
-- -- -- --
2880037 1


I think, according to A summary institutions, rules of

The result is:
Balance of institutions,
2880047288048288016288006
2880045288005 2
2880044 1
2880037 1


CodePudding user response:

Look at this line not line, can't again change,


The first method:
Select '2880047288048288016288006', the sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880047288048288016288006)
UNION ALL
Select '2880045288005', the sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880045288005)
UNION ALL
Select '2880034288033', the sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880034288033)
UNION ALL
Select '2880032288029', the sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880032288029)
UNION ALL
Select '2880012288014288046', the sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880012288014288046)
UNION ALL
Select '2880010288011', the sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880010288011)
UNION ALL
Select '2880009288013', the sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880009288013)
UNION ALL
Select '2880044', the sum (ckye), sum (dkye), sum (blye), sum (JLR) from think_daily_report where JGH in (2880044);
The second method:
Select '2880047288048288016288006',
Sum (CASE WHEN JGH (in 2880047288048288016288006) THEN ckye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880047288048288016288006) THEN dkye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880047288048288016288006) THEN blye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880047288048288016288006) THEN JLR ELSE 0 END)
The from think_daily_report UNION ALL
Select '2880045288005',
Sum (CASE WHEN JGH (in 2880045288005) THEN ckye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880045288005) THEN dkye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880045288005) THEN blye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880045288005) THEN JLR ELSE 0 END)
The from think_daily_report UNION ALL
Select '2880034288033',
Sum (CASE WHEN JGH (in 2880034288033) THEN ckye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880034288033) THEN dkye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880034288033) THEN blye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880034288033) THEN JLR ELSE 0 END)
The from think_daily_report UNION ALL
Select '2880032288029',
Sum (CASE WHEN JGH (in 2880032288029) THEN ckye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880032288029) THEN dkye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880032288029) THEN blye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880032288029) THEN JLR ELSE 0 END)
The from think_daily_report UNION ALL
Select '2880012288014288046',
Sum (CASE WHEN JGH (in 2880012288014288046) THEN ckye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880012288014288046) THEN dkye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880012288014288046) THEN blye ELSE 0 END),
Sum (CASE WHEN JGH (in 2880012288014288046) THEN JLR ELSE 0 END)
The from think_daily_report UNION ALL
Select '2880010288011',
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related