SQL 查詢惟一數據/查詢重複數據

 

//SQL 查詢惟一數據/查詢重複數據spa

--select  *  from MEMBER_FAVORITE where ROW_ID (not) in(
--select MAX(ROW_ID) from MEMBER_FAVORITE group by FAVORITE_TYPE,BLOCK_ID,MEMBER_ID
--)排序

 

1.FAVORITE_TYPE,BLOCK_ID,MEMBER_ID 惟一的標準。ip

2.無 not ,查詢結果是 上述信息 顯示惟一數據。it

3.有 not ,  是預備刪除的重複數據。io

 

 

//   row number over 分頁 select

       condition = @" SELECT * FROM(
                                            select TOP " + (skip + count) + @"  
                                            *,
                                            ROW_NUMBER()
                                             OVER(" + sortSql + @") AS ROWID
                                            from BASE_BLOCK block 
                                            where  ... order by ...
                                            ) AS TEMP1
                                            WHERE ROWID>" + skip;分頁

 

--ROW_NUMBER() 就是生成一個有順序的行號,而他生成順序的標準,就是後面緊跟的OVER(ORDER BY ID)
--還必須添加OVER語句以便告訴SQL Server你但願怎樣添加行序號,排序方式惟一,不然你會找不到你要的結果。數據

相關文章
相關標籤/搜索