Oracle如何取出某一列的所有不重複值作為單獨一列

2021-10-05 03:07:35 字數 4857 閱讀 2471

1樓:清茶稀飯

這個是oracle的行變列轉換 可以使用乙個函式 sys_connect_by_path(column,《分隔符》)

如select c.gysid, listagg(c.wzlbid,',') within group (order by c.

wzlbid) from wzgl_gys_zrwmfw c group by gysid

這幾個方法都可以實現行轉列,達到想要的效果。

但當資料量比較大時卻報ora-01489:字串連線的結果過長。

此時個人的解決辦法,只能轉到程式**中去處理。

希望,以此為鑑!

2樓:匿名使用者

用wmsys.wm_concat這個函式,如果你的庫中沒有這個函式,參照乙個這個**自己建立一下

3樓:匿名使用者

select a, wmsys.wm_concat(b) from atest t group by a

結果:a   1,2,1

b   1,3,2

select a, wmsys.wm_concat(b)from (select distinct a, b from atest) t

group by a

結果:a   2,1

b   3,2,1

4樓:海子

select distinct column_name from table_name

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

5樓:小丁創業

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

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

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

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

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

6樓:匿名使用者

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;

7樓:逗比一坨坨

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

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

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根據某乙個字段重複只取第一條資料

8樓:

使用分析函式row_number() over (partiion by ... order by ...)來進行分組編號,然後取分組標號值為1的記錄即可。

目前主流的資料庫都有支援分析函式,很好用。

其中,partition by 是指定按哪些字段進行分組,這些字段值相同的記錄將在一起編號;order by則是指定在同一組中進行編號時是按照怎樣的順序。

示例(sql server 2005或以上適用):

select s.*

from (

select *, row_number() over (partition by [手機號] order by [店鋪]) as group_idx

from table_name

) swhere s.group_idx = 1

9樓:匿名使用者

用group by 最後乙個字段 用個max()

10樓:發生等將發生

如果僅僅只是查詢出來去從,那麼就用distinctselect distinct 需要去重的列明(允許多列) from table

如果是需要在表中刪除,可以這樣處理

1、建立臨時表,將重覆記錄查詢出來去重插入到臨時表2、刪除實表中的重覆記錄

3、將臨時表中的記錄插入到實表

處理完成

11樓:匿名使用者

select * into ##tmp_table from 表where 1=2

declare @phoneno int

declare cur cursor forselect 手機號 from 表 group by 手機號open cur

fetch next from cur into @phonenowhile @@fetch_status=0begin

insert into ##tmp_tableselect top 1 from 表 where 手機號=@phoneno

fetch next from cur into @phonenoendselect * from ##tmp_tabledrop table ##tmp_table

12樓:匿名使用者

最簡單的 select distinct (手機號)

13樓:老漢肆

select

temp.id,

temp.device_id,

temp.update_dtm,

temp.test_result

from (

select

t.id,

t.device_id,

t.update_dtm,

t.test_result,

row_number() over(partition by device_id order by t.update_dtm desc) as row_***

from device_info_tbl t ) tempwhere temp.row_*** = '1'

如何獲得DataGridView中某一列中全部的值

寫個copyfor迴圈就行了 迴圈的個數就是你baidatagridview.rows.count 就是至於取du 出值來放到 就看你 zhi自己喜好了 string,hastable這些都可以daofor int x 0 x下標 tostring 迴圈每一行 foreach datarow row...

怎麼獲得GridView某一行某一列的值

以gridview控制項名稱為gv來說,this.gv.rows 0 cells 0 value,不能直接取出某列的全部值,因為 控制項是先按行後按列內使容用的。因此可以寫乙個迴圈 for或者foreach 遍歷所有行gv.rows,在當前行中獲取某列的資料。如前面的 如果單元格中加了其他控制項,還...

excel如何統計出一列資料中某一範圍的數值所佔比例

如圖,求a列中分數大於等於80小於90的個數所佔總數百分比。b2單元格輸入的是 sumproduct a2 a27 80 a2 a27 90 counta a a 1 b2單元格數字是百分比格式。1 新建乙個excel檔案並開啟該檔案。2 在檔案中隨意選擇一列並輸入一些資料,該列為統計資料的資料來源...