-
[sqlite] weekly & month statistics queryFrontend/react-native 2019. 11. 8. 12:15
운동 기록 records에서 주간별 볼륨합을 구해서 그래프로 변화를 표현하고자 한다.
(I'll calculate weekly & monthly volume sums and represent the changes in graph.)
[Weekly]
mysql:
SELECT DATE_FORMAT(DATE_SUB(today, INTERVAL (DAYOFWEEK(today)-1) DAY), '%Y/%m/%d') as start, DATE_FORMAT(DATE_SUB(today, INTERVAL (DAYOFWEEK(today)-7) DAY), '%Y/%m/%d') as end, DATE_FORMAT(`today`, '%Y%U') AS `date`, sum(volume) as volume FROM records GROUP BY date;
를 sqlite로 변경을 해야했다.
(I've to change it to sqlite.)
sqlite:
SELECT strftime('%Y-%m-%d', datetime(today, strftime('%w', datetime(today, '-1 days'), 'localtime')), 'localtime') as start, strftime('%Y-%m-%d', datetime(today, strftime('%w', datetime(today, '-7 days'), 'localtime')), 'localtime') as end, strftime('%Y%U', today, 'localtime') as date, sum(volume) as volume FROM records GROUP BY date;
Result:
[Monthly]
mysql:
SELECT MONTH(today) as date, sum(volume) as volume FROM records GROUP BY date;
to
sqlite:
SELECT strftime('%m', today) as date, sum(volume) as volume FROM records GROUP BY date;
Result:
Reference site:
https://bluexmas.tistory.com/626
https://javaexpert.tistory.com/180
https://codeday.me/ko/qa/20190525/625004.html
http://www.nazuni.pe.kr/web/dev/mysql/functions_datetime.php
https://stackoverflow.com/questions/650480/get-month-from-datetime-in-sqlite
'Frontend > react-native' 카테고리의 다른 글
[react-native] 리엑트 네이티브 버전 업그레이드 방법 (0) 2021.03.09 How to start react-native with ignite boilerplate. (0) 2020.04.29 [expo] Changing segment content onPress on react-native (0) 2019.11.06 [expo] react-native android 빌드시 아이콘(icon) 특수문자 깨짐 현상 해결 (0) 2019.10.17 [expo] vector icon (0) 2019.10.15