반응형


<확인>

*간단한 확인 
select now();

*Time Zone 설정이 되어 있지 않다면 0
select count(*) from mysql.time_zone;

*Time Zone 국가 (KST, EEST ..) 
select @@system_time_zone;

*Time Zone 정보 
 SELECT @@global.time_zone, @@session.time_zone;
> SYSTEM SYSTEM



<변경> 
vi /etc/my.cnf

set time_zone='-07:00'; 

추가후 

systemctl restart mysqld

확인
select now();

[출처]https://www.inmotionhosting.com/support/website/databases/how-to-change-mysql-server-time-zone

728x90
반응형
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
반응형

내부 쿼리에서 메인 쿼리의 데이터를 참조하는 방식인 상관서브쿼리(Correlated Subquery)를 사용하고 있습니다. 상관서브쿼리는 메인 쿼리 적용 테이블의 행마다 서브쿼리가 반복 실행되는 방식입니다. 일반적인 쿼리의 경우 서브 쿼리의 결과를 메인에서는 단순히 이용만 하지만 상관 서브 쿼리에서는 서브 쿼리가 메인 쿼리의 값을 이용하여 값을 구하면 그 값을 다시 메인 쿼리에서 이용하는 구조입니다.

Inner조인으로 쿼리하면 서로 키가 일치하는 데이터만 구할 수 있습니다. 여기서 구하고자 하는 데이터는 한쪽 테이블에 일치하는 정보가 없을 때 이므로 outer 조인으로 해결하거나 exists 구문을 사용해야 합니다.
exists는 처리결과로 boolean 값을 리턴하고 join은 처리결과로 테이블을 리턴하는 차이가 있습니다.

 

[출처]tacademy-데이터베이스 강의 참고자료

728x90

+ Recent posts