select name,
population,
area
from World
where area >= 3000000 or population >= 25000000
select product_id
from Products
where low_fats = 'Y' and recyclable = 'Y'
select name
from Customer
where id not in (select id from Customer where referee_id = 2)
select name as Customers
from Customers
where id not in (select customerId from Orders)
select employee_id,
case
when employee_id % 2 = 1 and left(name, 1) <> 'M' then salary
else 0
end as bonus
from Employees
order by employee_id
update Salary
set sex = case
when sex = 'f' then 'm'
when sex = 'm' then 'f'
end;
delete p2
from Person p1
inner join Person p2 on p1.email = p2.email
where p1.id < p2.id
select user_id,
concat(upper(left(name,1)), lower(substring(name,2))) as name
from Users
order by user_id
substr은 지정한 곳부터 모든 문자열을 불러올 수 있다!
select sell_date,
count(distinct product) as num_sold,
group_concat(distinct product) as products
from Activities
group by 1
order by 1
select patient_id,
patient_name,
conditions
from Patients
where conditions like '%DIAB1%'
select employee_id
from Employees
where employee_id not in (select employee_id from Salaries)
union
select employee_id
from Salaries
where employee_id not in (select employee_id from Employees)
order by employee_id
select db.product_id,
db.store,
db.price
from (
select product_id,
case when store1 is not null then 'store1' end as store,
store1 as price
from Products
union
select product_id,
case when store2 is not null then 'store2' end as store,
store2 as price
from Products
union
select product_id,
case when store3 is not null then 'store3' end as store,
store3 as price
from Products
) db
where db.price is not null or db.price <> 0
select id,
case
when p_id is null then 'Root'
when id in (select p_id from tree where p_id is not null) then 'Inner'
else 'Leaf'
end as type
from tree
group by id
SELECT
IFNULL(
(SELECT DISTINCT Salary
FROM Employee
ORDER BY Salary DESC
LIMIT 1 OFFSET 1),
NULL) AS SecondHighestSalary
[8주차]해커랭크 Basic Select 15 (0) | 2023.02.05 |
---|---|
[7주차] 리트코드: Day5 ~ Day9(1407, 1158) (0) | 2022.12.12 |
[5주차] 프로그래머스: JOIN, STRING, DATE (0) | 2022.12.08 |
[4주차] 프로그래머스: GROUP BY/ IS NULL/ JOIN (0) | 2022.11.22 |
[3주차] 프로그래머스: SUM, MAX, MIN / GROUP BY (1) | 2022.11.22 |