Now let us go through an interesting topic on CASE structure. Let us see how a CASE structure works. Consider the following statement: SELECT When the above query is executed, it returns four columns (empno, ename, jobfunction, sal). The only eye-catching issue from the above is the following structure: CASE job The above dictates something very similar to the following:
You need to observe that I specified the column (job) along with CASE. The conditions of WHEN work with the values available within that column. We can even work with different relational (and SQL) operators within the WHEN condition as shown in the following example: SELECT In the above case, the conditions are directly used within the WHEN statement and you need not specify any column with the CASE. Finally, you can even work with sub-queries within the CASE structure as follows: SELECT The above returns a new column named “pay,” which contains either “HIGH” or “LOW” based on their salary compared to the average salary of all employees.
blog comments powered by Disqus |