반응형
select
product_name,
ifnull(sum(if(date_format(order_date, '%Y') = '2015', cnt, 0)),0) as "2015",
ifnull(sum(if(date_format(order_date, '%Y') = '2016', cnt, 0)),0) as "2016"
from product a join product_order b
on a.product_id = b.product_id
group by product_name
==
select
product_name,
ifnull(sum(if(date_format(order_date, '%Y') = '2015', cnt, 0)),0) as "2015",
ifnull(sum(if(date_format(order_date, '%Y') = '2016', cnt, 0)),0) as "2016"
from product a, product_order b
where a.product_id = b.product_id
group by product_name
728x90
'[개발관련] > Database(Mysql)' 카테고리의 다른 글
GROUP BY 사용시 only_full_group_by 관련 에러 발생시 (0) | 2019.05.29 |
---|---|
[ Mysql] DB Time Zone 변경 (0) | 2019.04.08 |
상관서브쿼리(Correlated Subquery) (0) | 2019.04.07 |
NOT IN, NOT EXIST 정리 (0) | 2019.04.07 |
데이터베이스 데이터 유형 및 CHAR와 VARCHAR (0) | 2019.04.06 |