資料庫統計重複數量sql,sql怎麼查詢有重複資料的數量

時間 2022-04-27 07:40:07

1樓:匿名使用者

select id,sum(case when name='紅茶' then 1 else 0 end) as '紅茶'

,sum(case when name='綠茶' then 1 else 0 end)

as'綠茶'

,sum(case when name='黃茶' then 1 else 0 end) as '黃茶' from tablename

group by id

2樓:落月

select a.id,a.name1 as 'name1(紅茶)',a.name2 as 'name2(綠茶)',a.name3 as 'name3(黃茶)'

from

(select id,count([name]) as name1 from 表 where [name]='紅茶' group by id

)a join

(select id,count([name]) as name2 from 表 where [name]='綠茶' group by id

)b on a.id=b.id

join

(select id,count([name]) as name3 from 表 where [name]='黃茶' group by id

)c on a.id=c.id

按mssql寫的,不知道oracle是不是能執行,可能表的別名前需要加as一類的小問題存在。

sql統計行數,但是需要去重中間的重複資料

3樓:匿名使用者

select count(distinct **) from表 group by 使用者

sql查詢一個表中一列中統計重複資料的個數

4樓:

如統計班級和班級人數,語句:

select id,name,age,greade,班級人數 from a

inner join

(select greade,sum(id) 班級人數 from agroup by greade

) bon a.greade = b.greade

sql怎麼查詢有重複資料的數量

5樓:匿名使用者

彙總查詢,就是group by 欄位

sql查詢語句計算重複資料個數

6樓:匿名使用者

1、建立測試表,

create table test_count(id varchar2(20), value varchar2(20));

2、插入測試資料

insert into test_count values(1, 1);

insert into test_count values(2, 1);

insert into test_count values(3, 1);

insert into test_count values(4, 2);

insert into test_count values(6, 1);

insert into test_count values(7, 3);

insert into test_count values(8, 3);

insert into test_count values(9, 3);

insert into test_count values(10, 3);

commit;

3、查詢表中全量資料,select t.*, rowid from test_count t;

4、編寫sql,可以得到每一個value重複的個數,並按照由大到小排列;

select value, count(*) from test_count t group by value order by 2 desc

7樓:汐日南莘

sql 計算重複資料個數 可以使用 count 來統計例子personal表

id name

1 xm

2 xm

3 mx

統計personal表中name為xm的個數select count(name) total from personal where name='xm'

結果total2

8樓:

distinct 是去重複值!

select count(mypage) as s from deyebcount group by mypage order by mypage desc;

9樓:匿名使用者

select count(*),aa,,bb,cc from a gourp by aa,bb,cc

10樓:匿名使用者

select mypage,count(*) from deyebcount group by mypage order by mypage desc;

sql重複資料只顯示一條 並且統計重複次數

11樓:匿名使用者

你就沒說明白

select 欄位,count(*) from 表名 group by 欄位

看看是這意思不?

欄位和表名自己替換下

12樓:匿名使用者

select 姓名,身份證,max(家庭住址) 家庭住址,max(銀行帳號) 銀行帳號,max(備註) 備註,count(*) 重複條數

from tabname

group by 姓名,身份證

大致這樣(不過家庭住址、銀行帳號、備註 不是取最前面的,而是取了一個最大的)。

13樓:木木夕木

select * from (select 姓名,身份證,家庭住址,銀行帳號,備註,row_number() over (partition by 姓名,身份證 order by numrow desc) ss

from

(select 姓名,身份證,家庭住址,銀行帳號,備註,row_number() over (partition by 姓名,身份證 order by 姓名,身份證)  numrow from 表名)  aa ) bb

where ss='1'

有點麻煩,不過可以實現

14樓:甲國英善巳

如果只是按你的結果得到資料,則語句是:

select

名字,max(金額)

金額from

表group

by名字

但感覺金額應該是統計的,比如張三顯示230,則應該是select

名字,sum(金額)

金額\from

表group

by名字

sql: 查詢重複資料,並查詢出,指定條件下,該重複資料出現的次數 15

15樓:匿名使用者

--查詢指定條件下的重複次數

--測試資料

with tabname(id,name) as (select 1,'name1' union allselect 1,'name1' union allselect 1,'name1' union allselect 1,'name2' union allselect 1,'name2' union allselect 1,'name3' union allselect 2,'name1' union allselect 2,'name1' union allselect 2,'name2' union allselect 2,'name3' union allselect 3,'name1')

select id,(name1+name2+name3) as 重複次數,name1,name2,name3 from(

select id,name from tabname) as a

pivot(

count(name)

forname in (name1,name2,name3)) as b結果:

sql統計不重複條數

sqlserver 中查統計一張表中相同id的個數

16樓:

select id,count(0) from table1 group by id

用group by分組統計就行了。

17樓:匿名使用者

select count(id) from table1 where id=值

Mysql資料庫中多條重複資料,如何只刪除一條

蒯淑蘭費琬 這個需要分情況。1,你的資料庫表中有主鍵,且主鍵上面的資料為唯一值。也就是沒有重複值。那麼你在刪除的時候,將這個唯一值作為條件進行刪除。如 delete from 表名 where id 1 2.所有的資料相同,那麼你只能開啟資料表,手工選定其中某一條,進行刪除。 初懷雨步申 這條語句寫...

C插入資料庫,不能重複,怎麼防止資料庫中插入重複資料?

protected void submit click object sender,eventargs e 使用try 未出錯時執行的語句 catch exception ex 出錯是執行的語句finally 無論出錯與不出錯始終執行的語句用這個方法找找看是什麼問題,如果不好用最好把這段 抽成方法再...

資料庫查詢和統計問題,謝謝大家

11859947 對程式設計技術和sql感興趣的朋友歡迎加如這個群 與大家一起 mssqlserver技術 mysql中如何統計所查到的數量快說把 難度你是要知道的是 select count as 查詢到的數量 from 表 where 查詢條件 這樣的結果麼?掠環擁丙識季板宅戒喚冬適火滿各胖按獻...