简体   繁体   English

为什么使用DAYOFYEAR(DATE)的mysql查询将不同的结果返回DAY(DATE)?

[英]Why Does a mysql Query Using DAYOFYEAR(DATE) Return Different Results to DAY(DATE)?

Question as above really. 确实有上述问题。

Just to reiterate I have run two identical queries except for the DAY(DATE) and DAYOFYEAR(DATE) parts which are used in the Select and Group By clauses. 重申一下,我已经运行了两个相同的查询,除了在Select和Group By子句中使用的DAY(DATE)和DAYOFYEAR(DATE)部分。

I expected the results to be the same but they differ greatly (DAYOFYEAR returns 344563 results and DAY returns 253637 results). 我期望结果是相同的,但是它们之间却相差很大(DAYOFYEAR返回344563结果,而DAY返回253637结果)。 The only explanation I can think of is that January 1st gets grouped with February 1st and so forth because they share the same DAY value. 我能想到的唯一解释是1月1日与2月1日分组,依此类推,因为它们共享相同的DAY值。 However the result set doesn't seem to show that. 但是结果集似乎没有显示出来。

Any confirmation/explanation would be greatly appreciated. 任何确认/解释将不胜感激。

DAYOFMONTH() and DAY() are comparable. DAYOFMONTH()和DAY()是可比较的。 today they would both return 16, since today is the 16th of the month, and every month has a day 16. DAYOFYEAR() is a count of how many days since the start of the year. 今天他们都将返回16,因为今天是每月的16号,每个月都有一天16。DAYOFYEAR()是自年初以来多少天的计数。 it is something else entirely. 这完全是另外一回事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM