大家帮我看下这句分页怎么错了急!
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 子句或选择列表所包含的子查询中,并且要对其进行聚合的列是外部引用。
没看出有什么问题,测试了一下,也没有问题。应该不是这里报的错,楼主再调试一下:
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 ,
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