~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4) Count Number of Subjects per Student (Comma-Separated Data)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Question: Write a query to find the number of subjects for each student when the data is stored in a comma-separated format (e.g., s1, (20,40,50)).
Query:
SQL
SELECT
name,
LEN(marks) - LEN(REPLACE(marks, ',', '')) + 1 AS NumberOfSubjects
FROM StudentMarks;
No comments:
Post a Comment