1

我用mysql。这是我的sql

select *
from releases
where  id >
(
    select min(id) as x
    from releases 
    where released > "2011-12-01"
) 
limit 0,30 

这是对的。但我想找到 id 在范围内(不仅大于)的项目,如下所示:

select *
from releases
where  id >
    ((
        select min(id) as x , max(id) as y
        from releases 
        where released > "2011-12-01"
    ) as D ) D.x and id < D.y
limit 0,30 
4

2 回答 2

1

我会这样做:

select 
    *
from 
    releases,
    (select 
        min(id) as x, 
        max(id) as y
     from
        releases
     where released > "2011-12-01"
     ) as D   
where
    id between D.x and D.y
limit 0,30
于 2012-11-08T07:40:12.547 回答
0

试试这个:

SELECT r.* 
FROM releases r 
JOIN (SELECT MIN(id) minId, MAX(id) maxId FROM releases WHERE released > '2011-12-01') AS A ON r.id BETWEEN A.minId AND A.maxId 
LIMIT 0,30;
于 2012-11-08T07:47:32.753 回答