我想獲得表中最大重複的整數我嘗試了很多方法,但無法使其工作。我在尋找的結果是:計數重複的數據
"james";"108"
由於這108當我Concat的兩個領域LOCA + locb重複了兩次,但別人沒有我嘗試用以下樣本表結構和查詢sqlfiddle鏈接我想... sqlfiddle link
查詢我想的是:
select * from (
select name,CONCAT(loca,locb),loca,locb
, row_number() over (partition by CONCAT(loca,locb) order by CONCAT(loca,locb)) as att
from Table1
) tt
where att=1
please click這裏,所以你可以看到完整的示例表和查詢我試過了。
Edite:添加完整的表結構及數據:
CREATE TABLE Table1
(name varchar(50),loca int,locb int)
;
insert into Table1 values ('james',100,2);
insert into Table1 values ('james',100,3);
insert into Table1 values ('james',10,8);
insert into Table1 values ('james',10,8);
insert into Table1 values ('james',10,7);
insert into Table1 values ('james',10,6);
insert into Table1 values ('james',0,7);
insert into Table1 values ('james',10,0);
insert into Table1 values ('james',10);
insert into Table1 values ('james',10);
什麼我要找的是作爲價值被重複兩次在整個數據獲取(詹姆斯,108),還有的repetion (james,10)但是loca的值爲null,所以Zero值和Null值只能被視爲在兩個(loca,locb)中都有值。
排序由你的分區上並沒有真正意義相同的值。請將示例數據添加到您的問題 - SQLFiddle不是真的可靠,目前不適合我。 –
你好,謝謝我更新了樣本數據和數據.. – hi4ppl
'CONCAT(loca,locb)'沒有意義。 'concat()'是連接字符串(文本)的值,而不是數字 –