A. sql 過濾重復記錄並按倒序排列
Select Max(id) As Id,Title From TableName Group By Title Order By Id DescDistinct是去掉完全相同的記錄,因為你的id不同,所以沒用.我是這樣理解的,按id降序排序,按Title分組,相同的取ID最大,能達到你要的效果,查詢不止一個欄位時,其他欄位分別加上Max()或者Min()Select Max(id) As Id,Title,Max(FiledA),Max(FiledB) From TableName Group By Title Order By Id Desc
B. sql 去重並排序問題
select
distinct
name
from
a
where
eid
in(select
eid
from
b
group
by
eid)
要求查詢在b表出現過的企業名稱,不重復
這樣就夠了.至於根據時間倒敘
和結果沒影響.
C. sql 消除重復值按時間排序
方法一(該查詢會過濾掉除第一條外的其他重復數據):select * from Table where id in (select distinct(t1) from Table)
order by date asc
倒序把asc換成desc
方法二(指定某條重復數據,其它過濾)
select * from Table_1 where t1 <>11 --過濾掉所有為11的數據,t1如不是int型,加單引號
union
select * from Table_1 where id=2 --這里是指定要查的重復數據
order by date desc
D. SQL查詢去重復並排序
select distinct Name from A where EId in(select Eid from B group by Eid) 要求查詢在B表出現過的企業名稱,不重復 這樣就夠了.至於根據時間倒敘 和結果沒影響.
E. sql語句查詢兩張表所有數據,去除重復項降序排列
如果兩張表欄位一樣的話
select * from (select * from 表1 union select * from 表2) order by id desc
如果不一樣,那就選出需要選出的欄位即可
F. 請教一個sql去重排序求和的問題
我理解太差了,沒有看明白……
取和最大的前兩名
selecttop2namefrom(
selectname,sum(num)nfromtable
groupbyname)t
wheret.ndesc
不包含前兩名的所有人
selectnamefromtable
wherenamenotin(
selecttop2namefrom(
selectname,sum(num)nfromtable
groupbyname)t
wheret.ndesc
)
名字取出了,那麼現在就求和,前面的只是給你看看,最終綜合成下面這樣的一條語句,如果你需要效率高點,將notin修改為notexists,還有,你給的東東也不全,我就按照大概意思手打出來的,要是有錯誤,見諒,但是思路和這個差不多,你看看是不是你要的
前兩名分組求和
selecttop2name,nfrom(
selectname,sum(num)nfromtable
groupbyname)t
wheret.ndesc
unionall
其他的求和,使用union鏈接
select'其他',
(selectsum(num)fromtable
where
namenotin(
selecttop2namefrom(
selectname,sum(num)nfromtable
groupbyname)t
wheret.ndesc
))
G. SQL如何去重
1、首先創建一個臨時表,用於演示sqlserver語法中的去重關鍵字distinct的使用。本文以sqlserver資料庫為例演示,
IF OBJECT_ID('tempdb..#tmp1') IS NOT NULL DROP TABLE #tmp1;
CREATE TABLE #tmp1(
Col1 varchar(50),
Col2 int
);
H. sql排序去重順序
select distinct 列名 from 表名 order by 列名
I. sql語句去重
可以採用組函數Sql來實現:
第一:可以把重復的行找出來:
select Dept_Guid,Category_Guid from 表名 group by Dept_Guid,Category_Guid havingcount(*)>1;
第二:把這些數據插入到一個中轉表中;
SQL 略
第三:把原表中的重復數據刪除;
SQL 略
第四:把備份到中轉表中的唯一化之後的數據,再插入原來的表中。
SQL 略