+ -
当前位置:首页 → 问答吧 → 查询重复问题

查询重复问题

时间:2011-11-23

来源:互联网

Select TOP 4 a.detailsid,a.chrtitle,b.liveid, imgt=b.chrimage From [live] a Join [live_file] b On a.detailsid = b.liveid where jingjia=1 order by a.detailsid desc

输出4条信息 有三条重复 请问怎么排查重复 重复字段 b.chrimage 

麻烦给个实例 谢谢

作者: cckakaok   发布时间: 2011-11-23

对于同一个b.chrimage你其他字段怎么取!

作者: AcHerat   发布时间: 2011-11-23

SQL code
Select TOP 4   a.detailsid,a.chrtitle,b.liveid, imgt=b.chrimage 
From [live] a Join [live_file] b On a.detailsid = b.liveid 
where jingjia=1 
GROUP BY a.detailsid,a.chrtitle,b.liveid,b.chrimage 
order by a.detailsid desc

作者: roy_88   发布时间: 2011-11-23

输出4条信息 有三条重复 请问怎么排查重复 重复字段 b.chrimag
--------------
其它3字段不重復?

作者: roy_88   发布时间: 2011-11-23

SQL code

;with cte as(
Select TOP 4 a.detailsid,a.chrtitle,b.liveid, imgt=b.chrimage From [live] a Join [live_file] b On a.detailsid = b.liveid where jingjia=1
)
select detailsid,chrtitle,liveid,imgt from cte a where not exists(
select 1 from cte where imgt=a.imgt and detailsid>a.detailsid
)

作者: geniuswjt   发布时间: 2011-11-23

SQL code

;with cte as(
Select TOP 4 a.detailsid,a.chrtitle,b.liveid, imgt=b.chrimage 
From [live] a Join [live_file] b On a.detailsid = b.liveid 
where jingjia=1 order by a.detailsid desc
)
select detailsid,chrtitle,liveid,imgt from cte a where not exists(
select 1 from cte where imgt=a.imgt and detailsid>a.detailsid
or (detailsid=a.detailsid and liveid>a.liveid)
)


引用 4 楼 geniuswjt 的回复:
SQL code

;with cte as(
Select TOP 4 a.detailsid,a.chrtitle,b.liveid, imgt=b.chrimage From [live] a Join [live_file] b On a.detailsid = b.liveid where jingjia=1
)
select detailsid,chrtitle,liveid……

作者: geniuswjt   发布时间: 2011-11-23

引用 2 楼 roy_88 的回复:
SQL code
Select TOP 4 a.detailsid,a.chrtitle,b.liveid, imgt=b.chrimage
From [live] a Join [live_file] b On a.detailsid = b.liveid
where jingjia=1
GROUP BY a.detailsid,a.chrtitle,b.liveid,b.ch……


楼上直接执行后 还是有重复

作者: cckakaok   发布时间: 2011-11-23

4楼你写的什么版本的啊?

作者: cckakaok   发布时间: 2011-11-23

引用 6 楼 cckakaok 的回复:

引用 2 楼 roy_88 的回复:
SQL code
Select TOP 4 a.detailsid,a.chrtitle,b.liveid, imgt=b.chrimage
From [live] a Join [live_file] b On a.detailsid = b.liveid
where jingjia=1
GROUP BY a.detailsid,a.chrt……


有一個一字不相同都會出來多條

把重復列用 group by ,不重復的用select max(列)

作者: roy_88   发布时间: 2011-11-24

2005+,你是2000?
引用 7 楼 cckakaok 的回复:
4楼你写的什么版本的啊?

作者: geniuswjt   发布时间: 2011-11-24