-2

我需要仅使用 WHERE 子句检索客户创建的第一条记录。我不能使用 LIMIT、ORDER BY 等。

SELECT *
FROM mytable
WHERE customer_id = 1
  AND created = ? the earliest timestamp for that customer

编辑:预料到那些会问的人,这是我正在使用的当前框架中特定案例的限制。别担心。我只需要这样做。如果做不到,就告诉我做不到。

提前致谢。

Edit2:谢谢大家,但我也不能使用任何连接。还有更多的想法还是根本无法完成?

4

3 回答 3

1
SELECT * 
FROM mytable 
WHERE customer_id = 1 AND created IN (
    SELECT min(created) AS MinCreated
    FROM mytable
    WHERE customer_id = 1
)
于 2012-07-24T16:37:27.673 回答
0

...AND created = MIN(SELECT timestamp FROM mytable)这行得通吗?

于 2012-07-24T16:37:36.553 回答
0

你可以使用,

select * from mytable where customer_id = 1
  AND (select count(*) from mytable) <=1
于 2012-07-24T16:48:12.747 回答