sql 查詢表中某段不重複的所有資料

時間 2021-10-14 22:25:42

1樓:匿名使用者

select *

from tablea

where (number not in(select ta.numberfrom tablea as ta inner join

tablea as tb on ta.number = tb.number and ta.id <> tb.id))

2樓:匿名使用者

create table #a (

id int,

name varchar(4),

number int

);insert into #a

select 1, 'a', 123 union allselect 2, 'b', 152 union allselect 3, 'c', 123 union allselect 4, 'd', 520 union allselect 5, 'e', 300;

goselect

*from

#a main

where

not exists (

select 1

from #a sub

where main.id <> sub.id and main.number = sub.number

);go

id name number----------- ---- -----------2 b 152

4 d 520

5 e 300

(3 行受影響)

sql 查詢資料表後 在統計某一列資料不重複的數量

3樓:小丁創業

統計第一列不相同的個數的操作方法和步驟如下:

1、首先,建立測試表,**如下圖所示。

2、其次,完成上述步驟後,插入測試資料,**如下圖所示。

3、接著,完成上述步驟後,建立所需臨時表,**如下圖所示。

4、最後,完成上述步驟後,統計每一列不重複的資料量,如下圖所示。這樣,問題就解決了。

4樓:匿名使用者

1、建立測試表,

create table test_salesstatistics (goods_name varchar2(200),order_quantity varchar2(200),

delivery_date varchar2(200),store_abbreviation varchar2(200),

goodmodel  varchar2(200),workid varchar2(200),goodname  varchar2(200) );

2、插入測試資料,

insert into test_salesstatistics

select 'name_' || (level / 4),

level / 4,

sysdate - level,

level / 10,

level / 100,

level / 8,

'goods_' || (level / 4)

from dual

connect by level < 10000;

3、建立所需臨時表,

create table test_mid as

select store_abbreviation,

goodname,

goodmodel,

sum(order_quantity) as order_quantity,

workid

from (select goods_name,

order_quantity,

delivery_date,

store_abbreviation,

goodmodel,

workid,

goodname

from test_salesstatistics

where to_char(delivery_date) between '19980810' and '20000810'

group by store_abbreviation, goodmodel, workid, goodname

4、統計每一列不重複的資料量,

select count(distinct store_abbreviation) store_abbreviation,

count(distinct goodmodel) goodmodel,

count(distinct workid) workid ,

count(distinct goodname) goodname

from test_mid t;

5樓:逗比一坨坨

友善的提醒兩點,如有幫助還望採納,謝謝!

第一、你這個語句本身寫的有點麻煩,簡化如下

select [store_abbreviation]  ,[goodname], [goodmodel] ,sum(order_quantity) as order_quantity, [workid]

from [fangtaidata].[dbo].[salesstatistics]

where  [delivery_date]  between  '2014-07-02' and  '2014-07-25'

group by [store_abbreviation],[goodmodel],[workid],[goodname]

第二、統計不重複的數量也很簡單,再寫個語句

--只取第一列

select count(distinct store_abbreviation)

from [fangtaidata].[dbo].[salesstatistics]

where  [delivery_date]  between  '2014-07-02' and  '2014-07-25'

--想得到多列的數量

select count(distinct store_abbreviation) ,count(distinct goodname) ,count(distinct goodmodel) ,count(distinct workid)

from [fangtaidata].[dbo].[salesstatistics]

where  [delivery_date]  between  '2014-07-02' and  '2014-07-25'

碼字不易,如有幫助,還望採納,謝謝!

怎麼檢視資料庫表中某個欄位的值有哪些重複記錄

Sql查詢表中除了某個欄位以外的所有欄位的方法

select name from syscolumns where id select max id from sysobjects where xtype u and name 表名 然後去查不等於column1的值不就ok了 方法就這樣了,具體你自己寫去吧 有是有,不過要通過系統表來差,而且語句...

sql表中同時查詢兩個count的sql語句

可以有兩種解決方法。方法1 select name count 1 as 總題數 sum case when statu 1 then 1 else 0 end as 稽核題數 from question group by nme 方法2 select s.總題數,s.稽核題數,s.name fro...

怎麼查詢某表所有指定字元開頭的資料

select from 表名 where 欄位 like abc 查詢所有以abc開頭的資料。sql 語句,如何查詢某張表 或幾張表 中的所有欄位中,含有某指定字元的記錄?select a.b.from a,bwhere a.a1 and like key or a.a2 like key or l...