[英]min/max query with a where clause versus group by
Running MonetDB Database Server Toolkit v1.1 (Feb2013-SP6) 运行MonetDB数据库服务器工具包v1.1(2013年2月-SP6)
This query 这个查询
select rowtype, min(zdate), max(zdate) , count(*)
from fdhista
group by rowtype
;
returns correct minimum and maximum dates for each rowtype. 返回每个行类型的正确最小和最大日期。
rowtype L1 L2 L3
3 1970-12-31 2009-07-31 1664186
1 2003-02-24 2013-09-13 11649306
This query, over the same table 这个查询,在同一个表上
select min(zdate), max(zdate), count(*) from fdhista where rowtype=3;
seems to "ignore" the where clause, returning 似乎“忽略”了where子句,返回
L1 L2 L3
1970-12-31 2013-09-13 13313492
I haven't found a general sql precedent (yet) for that answer. 我还没有找到一个通用的sql先例(尚未)。 Is this the expected response? 这是预期的反应吗?
I was expecting this 我在期待这个
L1 L2 L3
1970-12-31 2009-07-31 1664186
I tried similiar queries in Oracle and SQL Server and get back my expected response. 我在Oracle和SQL Server中尝试了类似的查询,并取回了我预期的响应。 Yet I find generic sql comments that support "ignoring" the where clause. 然而,我发现支持“忽略”where子句的通用sql注释 。 Maybe this is a case of MonetDB's use of a specific SQL standard? 也许这是MonetDB使用特定SQL标准的情况?
Agreed, looks like a bug, but could not reproduce in this example: 同意,看起来像一个bug,但在这个例子中无法重现:
create table fdhista (rowtype tinyint, zdate date);
insert into fdhista values (1,'2013-09-13'),(1,'1970-12-31'),(3,'2013-09-14'),(3,'1970-12-30'),(3,'1984-06-24');
When I then run 当我跑的时候
select rowtype, min(zdate), max(zdate) , count(*) from fdhista group by rowtype;
I get 我明白了
+---------+------------+------------+------+
| rowtype | L1 | L2 | L3 |
+=========+============+============+======+
| 1 | 1970-12-31 | 2013-09-13 | 2 |
| 3 | 1970-12-30 | 2013-09-14 | 3 |
+---------+------------+------------+------+
And with the restriction 并有限制
select min(zdate), max(zdate), count(*) from fdhista where rowtype=3;
I get 我明白了
+------------+------------+------+
| L1 | L2 | L3 |
+============+============+======+
| 1970-12-30 | 2013-09-14 | 3 |
+------------+------------+------+
Everything looks fine, but I am running the latest MonetDB version here. 一切都很好,但我在这里运行最新的MonetDB版本。
So first, update to the latest MonetDB version Jan2014. 首先,更新到最新的MonetDB版本2014年1月。 Second, please report MonetDB bugs in the bugtracker at http://bugs.monetdb.org/ . 其次,请在http://bugs.monetdb.org/上的 bugtracker中报告MonetDB错误。 Please make sure to include enough information into the bug report so that it can be reproduced, I had to guess the schema and and come up with sample data in this case. 请确保在错误报告中包含足够的信息以便可以重现,我必须猜测模式,并在这种情况下提出样本数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.