--去重复计数
SELECT COUNT(DISTINCT pid) FROM B WHERE parentclass = '基础班'
--去重复查询
SELECT DISTINCT pid FROM B WHERE parentclass = '基础班'
#3
我是要select A表.* from A表 left join B表 on A表.pid=B表.pid where B表.parentclass='基础班',但这样A表会出现重复数据。而且我要求不出现重复数据的情况下分页。
#4
我要求分页!
#5
select A表.* from A表 join(SELECT pid,parentClass B表 where B表.parentclass='基础班' GROUP BY pid,parentClass)T on A表.pid=T.pid
#6
DECLARE @pageSize int
DECLARE @page int
SET @pageSize = 100
SET @page = 2
SELECT pid
FROM (
SELECT DISTINCT pid,
ROW_NUMBER() OVER (ORDER BY GetDate()) rn
FROM B
WHERE parentclass = '基础班'
) t
WHERE rn BETWEEN (@page-1)*@pageSize+1 AND @page*@pageSize
ORDER BY rn
#7
你好,我的是两个表哦?
#8
分页结果再和A关联啊!
反正有了不重负的pid,输出字段自己按需要调整。
#9
不好意思,我的是sql2000。
我琢磨了第一页的数据调用可以这样:
[code]select top 10 a.pid,a.name from A表 a LEFT JOIN B表 b ON a.pid=b.pid where b.parentclass='基础班' group by a.pid order by a.pid desc[/code]
但后面的页和count就不知道怎么写了
#10
select top 10 a.pid,a.name from A表 a LEFT JOIN B表 b ON a.pid=b.pid where b.parentclass='基础班' group by a.pid,a.name order by a.pid desc
#11
各位看我解决得对不对?
第一页:
select top 10 a.pid,a.name from A表 a left join B表 b ON a.pid=b.pid where b.parentclass='基础班' group by a.pid,a.name order by a.pid desc
第二页:
select top 10 a.pid,a.name from A表 a left join B表 b ON a.pid=b.pid where b.parentclass='基础班' and b.pid >(select min(pid) from (select top 10 pid from B表 where parentclass='基础班' group by pid order by pid desc) as tmp) group by a.pid,a.name order by a.pid desc
cout总数是这样吗?
select distinct count(*) from B表 where parentclass=‘基础班’
sql2000数据库,求指点!!如能优化更加感激不尽!
#12
第一页 没问题,前台需要记下本页最大pid
第二页 加条件
select top 10 a.pid,a.name
from A表 a
left join B表 b ON a.pid=b.pid
where b.parentclass='基础班'
and a.pid > @上页最大pid
group by a.pid,a.name
order by a.pid desc
select top 10 a.pid,a.name --top 10 其实不需要了
from A表 a
left join B表 b ON a.pid=b.pid
where b.parentclass='基础班'
and a.pid BETWEEN @页内最小pid AND @页内最大pid
group by a.pid,a.name
order by a.pid desc
#17
select #A.PID,#A.NAME,PARENTCLASS,MAX(CLASS) CLASS from #A JOIN #B on #A.PID=#B.PID
GROUP BY #A.PID,#A.NAME,PARENTCLASS
我是要select A表.* from A表 left join B表 on A表.pid=B表.pid where B表.parentclass='基础班',但这样A表会出现重复数据。而且我要求不出现重复数据的情况下分页。
#4
--去重复计数
SELECT COUNT(DISTINCT pid) FROM B WHERE parentclass = '基础班'
--去重复查询
SELECT DISTINCT pid FROM B WHERE parentclass = '基础班'
我要求分页!
#5
select A表.* from A表 join(SELECT pid,parentClass B表 where B表.parentclass='基础班' GROUP BY pid,parentClass)T on A表.pid=T.pid
#6
DECLARE @pageSize int
DECLARE @page int
SET @pageSize = 100
SET @page = 2
SELECT pid
FROM (
SELECT DISTINCT pid,
ROW_NUMBER() OVER (ORDER BY GetDate()) rn
FROM B
WHERE parentclass = '基础班'
) t
WHERE rn BETWEEN (@page-1)*@pageSize+1 AND @page*@pageSize
ORDER BY rn
#7
DECLARE @pageSize int
DECLARE @page int
SET @pageSize = 100
SET @page = 2
SELECT pid
FROM (
SELECT DISTINCT pid,
ROW_NUMBER() OVER (ORDER BY GetDate()) rn
FROM B
WHERE parentclass = '基础班'
) t
WHERE rn BETWEEN (@page-1)*@pageSize+1 AND @page*@pageSize
ORDER BY rn
你好,我的是两个表哦?
#8
分页结果再和A关联啊!
反正有了不重负的pid,输出字段自己按需要调整。
#9
分页结果再和A关联啊!
反正有了不重负的pid,输出字段自己按需要调整。
不好意思,我的是sql2000。
我琢磨了第一页的数据调用可以这样:
[code]select top 10 a.pid,a.name from A表 a LEFT JOIN B表 b ON a.pid=b.pid where b.parentclass='基础班' group by a.pid order by a.pid desc[/code]
但后面的页和count就不知道怎么写了
#10
select top 10 a.pid,a.name from A表 a LEFT JOIN B表 b ON a.pid=b.pid where b.parentclass='基础班' group by a.pid,a.name order by a.pid desc
#11
各位看我解决得对不对?
第一页:
select top 10 a.pid,a.name from A表 a left join B表 b ON a.pid=b.pid where b.parentclass='基础班' group by a.pid,a.name order by a.pid desc
第二页:
select top 10 a.pid,a.name from A表 a left join B表 b ON a.pid=b.pid where b.parentclass='基础班' and b.pid >(select min(pid) from (select top 10 pid from B表 where parentclass='基础班' group by pid order by pid desc) as tmp) group by a.pid,a.name order by a.pid desc
cout总数是这样吗?
select distinct count(*) from B表 where parentclass=‘基础班’
sql2000数据库,求指点!!如能优化更加感激不尽!
#12
第一页 没问题,前台需要记下本页最大pid
第二页 加条件
select top 10 a.pid,a.name
from A表 a
left join B表 b ON a.pid=b.pid
where b.parentclass='基础班'
and a.pid > @上页最大pid
group by a.pid,a.name
order by a.pid desc
#13
去重字段加个MAX就好 了,count(*)就是求总数,只有一个结果不需要distinct
#14
去重字段加个MAX就好 了,count(*)就是求总数,只有一个结果不需要distinct
因为是两个表left join 所有有重复的行的。
#15
第一页 没问题,前台需要记下本页最大pid
第二页 加条件
select top 10 a.pid,a.name
from A表 a
left join B表 b ON a.pid=b.pid
where b.parentclass='基础班'
and a.pid > @上页最大pid
group by a.pid,a.name
order by a.pid desc
select top 10 a.pid,a.name --top 10 其实不需要了
from A表 a
left join B表 b ON a.pid=b.pid
where b.parentclass='基础班'
and a.pid BETWEEN @页内最小pid AND @页内最大pid
group by a.pid,a.name
order by a.pid desc
#17
去重字段加个MAX就好 了,count(*)就是求总数,只有一个结果不需要distinct
因为是两个表left join 所有有重复的行的。
select #A.PID,#A.NAME,PARENTCLASS,MAX(CLASS) CLASS from #A JOIN #B on #A.PID=#B.PID
GROUP BY #A.PID,#A.NAME,PARENTCLASS