日期:2014-05-17  浏览次数:20474 次

大家帮我看下这句分页怎么错了急!
select distinct top 10 a.title,address,meetRemark,city,star,a.id,a.pic,a.meetPic from hotel a,meet b,mprice c 
where a.id >(select max(id) from (select distinct top 10 a.id from hotel a,meet b,mprice c where a.isDel=0 and 
a.id=b.hid and b.id=c.mid  order by a.id asc) as tblTmp) and a.isDel=0 and a.id=b.hid and b.id=c.mid 
 order by a.id asc



出错:聚合不应出现在 WHERE 子句中,除非该聚合位于 HAVING 子句或选择列表所包含的子查询中,并且要对其进行聚合的列是外部引用。

------解决方案--------------------
try this,

select distinct top 10 a.title,address,meetRemark,city,star,a.id,a.pic,a.meetPic 
from hotel a,meet b,mprice c 
where a.id>
(select max(id) 
 from (select distinct top 10 a.id from hotel a,meet b,mprice c 
       where a.isDel=0 and a.id=b.hid and b.id=c.mid) as tblTmp) 
and a.isDel=0 and a.id=b.hid and b.id=c.mid 
order by a.id asc

------解决方案--------------------
引用:
有人知道不

没看出有什么问题,测试了一下,也没有问题。应该不是这里报的错,楼主再调试一下:
CREATE TABLE #hotel(id INT, isDel INT, title VARCHAR(10), [address] VARCHAR(10), city VARCHAR(10), star INT)
INSERT #hotel(id,isDel) SELECT 1, 0
CREATE TABLE #meet(id INT, hid INT)
INSERT #meet SELECT 1, 1 UNION ALL SELECT 1, 2
CREATE TABLE #mprice(mid INT)
INSERT #mprice(mid) SELECT 1

SELECT DISTINCT TOP 10
        a.title ,
        address ,
        --meetRemark ,
        city ,