Tip on using the CASE expression.
Tip on using the CASE expression.
Rating:
You must use the CASE expression if many calculations are being performed by using multiple queries on same row of a table. The following example shows how you should use the CASE expression rather than using the multiple queries:
FROM students
WHERE mark<50;
FROM students
WHERE mark BETWEEN 50 AND 75;
students
WHERE mark>75
Rather than using the above individual queries, you can perform the above operation in a single query by using the CASE expression as given below:
COUNT(CASE WHEN mark<50 THEN 1 ELSE null END) fail,
COUNT(CASE WHEN mark BETWEEN 50 AND 75 THEN 1 ELSE null END) fdiv,
COUNT(CASE WHEN mark> THEN 1 ELSE null END) distinction
FROM students;
Rating:
Other articles
- What is the DB_RECOVERY_FILE_DEST_SIZE initialization parameter?
- What is a view?
- What is a complete recovery?
- What is the portlist.ini file?
- Relational Algebra
