SELECT
order_id
, product_id
, DATE_FORMAT(out_date, '%Y-%m-%d') AS out_date
, CASE
WHEN out_date IS NULL THEN '출고미정'
WHEN out_date < '2022-05-02' THEN '출고완료'
ELSE '출고대기'
END AS "출고여부"
FROM
food_order
ORDER BY
order_id
;
WITH fo AS (
SELECT order_id
, product_id
, DATE_FORMAT(out_date, '%Y-%m-%d') out_date
FROM food_order
)
SELECT fo.*
, CASE
WHEN out_date <= '2022-05-01' THEN '출고완료'
WHEN out_date > '2022-05-01' THEN '출고대기'
ELSE '출고미정'
END "출고여부"
FROM fo
ORDER BY order_id;
SELECT fo.*
, CASE
WHEN out_date <= '2022-05-01' THEN '출고완료'
WHEN out_date > '2022-05-01' THEN '출고대기'
ELSE '출고미정'
END "출고여부"
FROM (
SELECT order_id
, product_id
, DATE_FORMAT(out_date, '%Y-%m-%d') out_date
FROM food_order
) fo
ORDER BY order_id;
2022년 5월 1일까지 출고완료
를 어떻게 표현하는 게 좋을까?
- out_date < '2022-05-02'
- out_date <= '2022-05-01'
(
SELECT order_id, product_id, date_format(out_date,'%Y-%m-%d') as out_date, '출고완료' as '출고여부'
FROM food_order
where out_date<='2022-05-01'
)
union
(
SELECT order_id, product_id, date_format(out_date,'%Y-%m-%d') as out_date, '출고대기' as '출고여부'
FROM food_order
where out_date>'2022-05-01'
)
union
(
SELECT order_id, product_id, date_format(out_date,'%Y-%m-%d') as out_date, '출고미정' as '출고여부'
FROM food_order
where out_date is null
)
SELECT
unique_id
, name
FROM
employees e
LEFT JOIN employeeUNI eu
USING(id)
SELECT unique_id, name from EmployeeUNI as eu
right join Employees as e
On e.id = eu.id;
SELECT (
SELECT
unique_id
FROM
EmployeeUNI
WHERE
EmployeeUNI.id = Employees.id
) AS unique_id
, name
FROM
Employees
;
SELECT
product_name
, year
, price
FROM
sales s
JOIN product p
USING(product_id)
select b.product_name , a.year , a.price from Sales a left join Product b on a.product_id=b.product_id;
def solution(absolutes, signs):
answer = []
for i in range(len(absolutes)):
if signs[i]:
answer.append(absolutes[i])
else:
answer.append(-absolutes[i])
return sum(answer)
def solution(absolutes, signs):
answer = 0
for i in range(len(absolutes)):
if signs[i]:
answer += absolutes[i]
else:
answer += absolutes[i]*(-1)
return answer
def solution(absolutes, signs):
answer=0
for absolute,sign in zip(absolutes,signs):
if sign:
answer+=absolute
else:
answer-=absolute
return answer
→ one-line if절
def solution(absolutes, signs):
return sum(absolutes if sign else -absolutes for absolutes, sign in zip(absolutes, signs))