SELECT FROM_UNIXTIME(start_date, '%Y-%m') as sdate, COUNT(*) AS cnt, SUM(total_amount) AS salesNum FROM xe_yeyak_res GROUP BY sdate ORDER BY sdate DESC

 

데이터

2.PNG

 

결과

1.PNG

 

xe 스키마에서 타입은 date로 해두었습니다.

  • profile

    자답입니다.

    xml 스키마에서 date type 라도 실제 db type 가 varchar 였던걸 깜빡 했습니다.

     

    select date_format(start_date,'%Y-%m') as sdate, COUNT(*) AS cnt, SUM(total_amount) AS salesNum FROM xe_yeyak_res GROUP BY sdate ORDER BY sdate DESC

     

    결과:

    3.PNG

     

  • profile

    XE의 date type은 유닉스 타임이 아니죠 ㅠㅠ

     

    날짜가 아닌 값에 굳이 date_format 함수를 사용해서 날짜로 인식하도록 하는 것보다는

    LEFT(start_date, 6) 이렇게 앞 6글자(201702)만 뽑아오는 것이 성능은 더 좋을지도 모릅니다.

  • profile profile
    굳이 date 관련 함수를 사용할 필요는 없겠네요.
    감사합니다^^