Home > database >  Grouping sum after how null values and other results calculated
Grouping sum after how null values and other results calculated

Time:09-18

Data as follows, because a statement execution result is empty, and the second value addition results or empty, how to avoid the wrong results
Bosses, please help, thank you
The table name: Class1 table name: Class2
Student Course Score - column names Student Course Score - column name
Zhang SAN's 78 zhang SAN's language is 78
Li si Chinese 78 li si math 78
Fifty and Chinese 80

 with c1 as (select sum (Score) s, a student from Class1 where student='Cathy' group by student), 

C2 as (select sum (Score) s, student from Class2 where student='Cathy' group by student),

The select c1. S + c2. S from c1 and c2




CodePudding user response:

ISNULL (c1) s, 0)

CodePudding user response:

reference 1st floor RINK_1 response:
ISNULL (c1) s, 0)
ISNULL (after) or empty, tried

CodePudding user response:

 WITH c1 AS (
SELECT SUM (Score) s, student
The FROM Class1
WHERE the student='Cathy'
GROUP BY
Student
),
C2 AS (
SELECT SUM (Score) s, student
The FROM Class2
WHERE the student='Cathy'
GROUP BY
Student
)
SELECT SUM (ss) AS ss
The FROM (
The SELECT ISNULL (c1) s, 0) AS ss FROM c1
UNION ALL
The SELECT ISNULL (c1) s, 0) AS ss FROM c2
) AS tt
  • Related