Then, you can use HAVING clause to filter out the students having atleast two unique courses subscribed to (which would be 1 and 3 in this case): SELECT student_name FROM your_table_name WHERE course_number IN (1,3) GROUP BY student_name HAVING COUNT (DISTINCT course_number) = 2
Full Answer
Each condition in the having clause counts the number of students taking the particular courses. The > 0 says that there is at least one. If you want to add a third or fourth set of courses, that is very easy by adding more conditions in the HAVING clause. Thanks for contributing an answer to Stack Overflow!
If you have a different dataset (say course_numbers 1,2,3) you can use course_number in (1,2,3) and COUNT (distinct course_number) = 3 and so on. Show activity on this post. You can approach this problem using conditional aggregation based filtering.
Each condition in the having clause counts the number of students taking the particular courses. The > 0 says that there is at least one. If you want to add a third or fourth set of courses, that is very easy by adding more conditions in the HAVING clause.
Firstly, get all the students who are either enrolled IN (..) course no (1, 3). Then, you can use HAVING clause to filter out the students having atleast two unique courses subscribed to (which would be 1 and 3 in this case):
SELECT statement is used to get name and marks of top three students.SQL query is. SELECT Name, Marks FROM Student s1 where 3 <= (SELECT COUNT(*) FROM Students s2 WHERE s1.marks = s2.marks)SQL (Structured Query Language) ... Functions of SQL (Structured Query Language)
Q6) Which of the following query will find all the unique students who have taken more than one course? Option D would be a right option. This query will first apply self join on enrolled table and then it evaluate the condition e1. sid = e2.
How to select all data from student table starting the name from letter 'r'?A. SELECT * FROM student WHERE name LIKE 'r%';SELECT * FROM student WHERE name LIKE '%r%';SELECT * FROM student WHERE name LIKE '%r';SELECT * FROM student WHERE name LIKE '_r%';
To get the number of students who are registered for more than 5 courses you do this... SELECT COUNT(*) FROM REGISTRATION WHERE SEMESTER = 'GIVEN SEMESTER' GROUP BY CAMPUS, STUDENT_ID HAVING COUNT(*) > 5; You need to group by campus AND student id since student id is repeated for different campuses.
Contents:Sample Select statement.Select with distinct on two columns.Select with distinct on three columns.Select with distinct on all columns of the first query.Select with distinct on multiple columns and order by clause.Count() function and select with distinct on multiple columns.
The SQL SELECT DISTINCT Statement The SELECT DISTINCT statement is used to return only distinct (different) values. Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.
SELECT statements An SQL SELECT statement retrieves records from a database table according to clauses (for example, FROM and WHERE ) that specify criteria. The syntax is: SELECT column1, column2 FROM table1, table2 WHERE column2='value';
With SQL, how do you select all the records from a table named “Persons” where the value of the column “FirstName” ends with an “a”? Explanation: The SQL LIKE clause is used to compare a value to similar values using wildcard operators. 3.
SELECT * FROM student WHERE name LIKE '%p';
SELECT COUNT(column_name) counts the non-null values of column in the table. The total number of STU_DEPT values in above table are 7 but one of them is null. Since count(column_name) counts non-null values of the given column, thus the output is 6.
Order by clause is used with SELECT statement for arranging retrieved data in sorted order. The Order by clause by default sorts the retrieved data in ascending order. To sort the data in descending order DESC keyword is used with Order by clause.
Answer. Answer: Which of the Query is used to Select all the Students from City = "Pune".