统计第一列不相同的个数的操作方法和步骤如下:
1、首先,创建测试表,代码如下图所示。
2、其次,完成上述步骤后,插入测试数据,代码如下图所示。
3、接着,完成上述步骤后,创建所需临时表,代码如下图所示。
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;
友善的提醒两点,如有帮助还望采纳,谢谢!
第一、你这个语句本身写的有点麻烦,简化如下
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'
码字不易,如有帮助,还望采纳,谢谢!
SELECT [Store_Abbreviation] ,COUNT(*)
FROM (select [Goods_Name],[Order_Quantity],[Delivery_Date],[Store_Abbreviation],[Goodmodel] ,[Workid],[Goodname] from
[fangtaidata].[dbo].[SalesStatistics]
where [Delivery_Date] between '2014-07-02' and '2014-07-25'
) AS QT
GROUP BY [Store_Abbreviation]
having count(*)=1
;
显示第一列不重复的数据