Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我无法通过这样的 SELECT 查询从数据库中检索某些数据:
SELECT table.something FROM table WHERE table.date BETWEEN 'from' AND 'to' GROUP BY (each 6 months between the from and to date).
知道如何做到这一点,而不必通过代码重复到视图和外部分组。
像这样的东西会起作用:
SELECT table.something, CEIL(MONTH(date)/6) as monthVALUE FROM table WHERE table.date BETWEEN 'from' AND 'to' GROUP BY monthVALUE
而不是担心在单个查询上创建一个带有开始日期和结束日期以及您的其他列的临时表插入记录。并使用每条记录的选择查询来获取结果并将其存储在临时表中并选择临时表。