Lowe’s Interview Questions | Over-weight
Question
Suppose in class, you have 3n boys and 2n girls with their names tabulated along with their weight and gender. Write a SQL query to separate students alphabetically who are over-weight (55kg for girls, 75kg for boys)
in progress
0
SQL
55 years
11 Answers
1741 views
Great Grand Master 2
Answers ( 11 )
select name,gender if(gender=’M’, weight>’75kgs’,weight>’55kgs’) as weights from table_name;
select *
from table_name
where gender = ‘Male’ and weight > ’75kg’
union all
select *
from table_name
where gender = ‘Female’ and weight > ’55kg’
select * from table_name where gender=’M’ and weight >75 or gender=’F’ and weight >55;
select * from table_name where (gender=’male’ and weight>75) or (gender=’female’ and weight>55) order by name;
SELECT * FROM students
WHERE (gender = ‘M’ AND weight > 75) OR(gender = ‘F’AND weight > 55)
ORDER BY name
select * FROM students where (gender = ‘M’ and weight > 75) or (gender = ‘F’AND weight > 55) order by name;
select * from table_name where (gender=’male’ and weight>75) or (gender=’female’ and weight>55) order by name;
Select name,gender from
(select name,gender ,if(gender=’m’,weight >’75’,weight>’55’) as weights
from names
having weights =1
order by name) as s;
select name, gender, weight
from table
where
(gender=’male’ and weight>= 75)
or
(gender =’female’ and weight >= 55)
order by name asc
SELECT *
FROM table
WHERE (lower(gender)=’female’ and Cast (weight AS INT) >55)
OR (lower(gender)=’male’ and Cast(weight AS INT) > 75)
ORDER BY name;
SELECT *
FROM table_name
WHERE (lower(gender)=’female’ and Cast (weight AS INT) >55)
OR (lower(gender)=’male’ and Cast(weight AS INT) > 75)
ORDER BY name;