在SQL中处理timastamp数据

针对timestamp数据,可以使用DATE_TRUNC或者DATE_PART来截取时间元素。
DATE_TRUNC
https://blog.modeanalytics.com/date-trunc-sql-timestamp-function-count-on/

SELECT DATE_TRUNC('day', occurred_at) AS day,
       user_id
  FROM benn.fake_fact_events
 WHERE event_name = 'complete_signup'
   AND occurred_at >= '2014-03-10'
   AND occurred_at <= '2014-05-26'
 ORDER BY 1 DESC

DATE_PART
http://www.postgresqltutorial.com/postgresql-date_part/

SELECT DATE_PART('dow', occurred_at) day_of_week,
       SUM(total) total_qty
  FROM orders
 GROUP BY 1
 ORDER BY 2 DESC;

你可能感兴趣的:(在SQL中处理timastamp数据)