Skip to content

Commit 968e8e7

Browse files
authored
Merge pull request #370 from HrishiDhondge/main
Code for SQL-435 issue
2 parents f83f1f5 + 09fbc01 commit 968e8e7

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- Only for MySQL and SQL Server --
2+
SELECT COUNT(DISTINCT textbook, credits) AS unique_count FROM Course;
3+
4+
-- Only for PostgreSQL --
5+
SELECT COUNT(DISTINCT(textbook, credits)) AS unique_count FROM Course;
6+
7+
-- Works for MySQL, PostgreSQL, and SQL Server --
8+
-- Using Subquery --
9+
SELECT COUNT(*) AS unique_count FROM (SELECT DISTINCT textbook, credits FROM Course) temp_course;
10+
11+
-- Using CONCAT function --
12+
SELECT COUNT(DISTINCT CONCAT(textbook, '--', credits)) AS unique_count FROM Course;
13+
SELECT COUNT(DISTINCT CONCAT(textbook, '--', credits)) AS unique_count FROM Course WHERE department_id = 4;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SELECT COUNT(DISTINCT textbook) FROM Course;
2+
SELECT COUNT(DISTINCT textbook) AS unique_textbook_count FROM Course;

0 commit comments

Comments
 (0)