2

我有一个简单的 MySQL 选择语句:

SELECT COUNT(*) AS COUNT FROM MY_TABLE WHERE TIME_STAMP > ?

但是,如果最早行的 TIME_STAMP 大于我的 WHERE 阈值,我不想计算第一行/最早行。就像是:

SELECT COUNT(*) AS COUNT FROM MY_TABLE WHERE TIME_STAMP > ? AND TIME_STAMP > $earliest

显然,我可以通过额外的先前查询获得最早的 TIME_STAMP。但我在徘徊,如果我能做到这一切。我试过了,但抛出了“无效使用组函数”错误:

SELECT COUNT(*) AS COUNT FROM MY_TABLE WHERE TIME_STAMP > ? AND TIME_STAMP > MIN(TIME_STAMP)

有什么建议么?谢谢

4

1 回答 1

2

如果您MIN从嵌套选择中获取值,您的最​​后一个查询将起作用。组功能需要上下文,你最想要什么?

SELECT COUNT(*) AS COUNT FROM MY_TABLE WHERE TIME_STAMP > ? AND TIME_STAMP > (SELECT   MIN(TIME_STAMP) FROM MY_TABLE)
于 2011-03-15T13:05:42.023 回答