Click here to Skip to main content
15,886,091 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

Here is the query.

Select grade as g1, grade as g2 from Student where
(Marks > 75 and Marks <90) -- for g1
or (Marks > 40 and Marks <75) for g2

I want to display the single column with multiple condition in where clause.

Here grade is single column.

Could you please suggest how to proceed further.

What I have tried:

Tried sub queries which is hitting performance like anything.
Posted
Updated 30-Jun-22 4:28am

1 solution

If I understood your question correctly perhaps something like
SQL
select 
   case 
      when marks > 75 and marks < 90 then grade
      else null
   end as g1,
   case 
      when marks > 40 and marks <= 75 then grade
      else null
   end as g2
from student 
where marks > 40 and marks < 90
 
Share this answer
 
Comments
nsvrao 30-Jun-22 12:17pm    
Either of grade column is becoming NULL with the above query.
Wendelius 30-Jun-22 14:24pm    
Any example data?
nsvrao 1-Jul-22 2:28am    
select
case
when ((marks > 75 and marks < 90) and (marks > 50 and marks < 75)) then grade
else null
end as g1,
case
when ((marks > 40 and marks <= 50)and (marks > 30 and marks <= 40)) then grade
else null
end as g2
from student
where marks --- wanted to know what will be exact condition to be placed in where condition
Wendelius 1-Jul-22 13:54pm    
Do you have any example data to try with?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900