Skip to content

Commit 9795fb2

Browse files
authored
Merge pull request #344 from HrishiDhondge/main
SQL-446: How to SUM DISTINCT Rows in SQL
2 parents add7df7 + 9648e77 commit 9795fb2

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SELECT SUM(credits) FROM (SELECT DISTINCT textbook, credits FROM Course) AS distinct_rows;
2+
SELECT SUM(credits) AS distinct_credits FROM (SELECT DISTINCT textbook, credits FROM Course) AS distinct_rows;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WITH unique_textbooks AS (SELECT DISTINCT textbook, credits FROM Course) SELECT SUM(credits) FROM unique_textbooks;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SELECT SUM(credits) AS distinct_credits FROM (SELECT textbook, credits FROM Course UNION SELECT textbook, credits FROM Course) AS combined;
2+
SELECT textbook, credits FROM Course UNION SELECT textbook, credits FROM Course;

0 commit comments

Comments
 (0)