You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在SQL中从timestamp字段提取星期几并按天统计数据

Got it! To extract the day of the week from your created timestamp column and aggregate counts per day, here's how you can do it across common SQL dialects:

PostgreSQL

Use the to_char() function with 'FMDay' to get clean, un-padded day names:

SELECT 
  to_char(created, 'FMDay') AS day_of_week,
  COUNT(*) AS total_entries
FROM surveys
GROUP BY day_of_week
ORDER BY total_entries DESC;

MySQL

Leverage the built-in DAYNAME() function which directly returns the full name of the day:

SELECT 
  DAYNAME(created) AS day_of_week,
  COUNT(*) AS total_entries
FROM surveys
GROUP BY day_of_week
ORDER BY total_entries DESC;

SQL Server

Use DATENAME() with the weekday argument to fetch the day name:

SELECT 
  DATENAME(weekday, created) AS day_of_week,
  COUNT(*) AS total_entries
FROM surveys
GROUP BY DATENAME(weekday, created)
ORDER BY total_entries DESC;

Result for Your Sample Data

When you run any of these queries against your provided data, you'll get the following output (formatted as you requested):

  • Monday - 4
  • Tuesday - 3
  • Friday - 1

内容的提问来源于stack exchange,提问作者Jaxon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:59:32