save up to 40%

Tip on using the CASE expression.

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

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:

SELECT COUNT (*)
   FROM students
   WHERE mark<50;


SELECT COUNT(*)
   FROM students
   WHERE mark BETWEEN 50 AND 75;


SELECT COUNT(*)
   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:

SELECT
   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

Click here to Article home

 
uCertify.com | Our Company | Articles | Privacy | Security | Contact Us | News and Press Release | uCertify India
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.