SnapshotTable数据每天跟踪随时间的变化

时间:2016-06-29 08:01:20

标签: sql sql-server-2008

所有

我希望创建一个每天运行的查询,并收集保留在给定字段中的值。

本练习的目的是完成我称之为“空白分析”的内容。对于每个公司实体,我们应该记录他们在10个关键投资组合领域的现有解决方案。游戏的目的是从实体中删除空白区域。

每个记录所有者将创建一行,并且将使用正在运行查询的datye标记日期。其他列将计算已收到条目的字段数。

这应该让我可以弄清楚每个客户经理可以了解他们的客户群以及跟踪一段时间内的变动情况。

查询需要为我们运行查询的每一天创建一个新行,以便我计算一段时间内的变化。

这是我的目标表。

CREATE TABLE [dbo].[ProfileScore](
[Date] [date] NULL,
[owneridname] [nvarchar](50) NULL,
[Cyber] [nvarchar](50) NULL,
[Encryption] INT NULL,
[Firewall] INT NULL,
[PCIDSS] INT NULL,
[asvscanner] INT NULL,
[pentest] INT NULL,
[phish] INT NULL,
[Scanner] INT NULL,
[TwoFactor] INT NULL,
[customertype] INT NULL,

源数据看起来像这样

owneridname cyber   encryption  firewall    pcidss  asvscanner  pentest phish   scanner twofactor   customertype
Dave NULL   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Customer
Dave NULL   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Customer
CRMSERVICE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Customer
Joey NULL   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Customer
Daniel NULL NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Customer
CRMSERVICE  NULL    NULL    No Opportunity  NULL    NULL    NULL    NULL    NULL    NULL    Customer
Kenny NULL  NULL    WatchGuard  NULL    NULL    NULL    NULL    NULL    NULL    Customer
Daniel NULL NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Customer
Matt NULL   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Customer
CRM Guest 01    NULL    NULL    NULL    No  -- Not Applicable --    Yes NULL    NULL    NULL    Customer

结果表... 对于每个给定的日期,我想为每个所有者排一行。 然后,每列将计算每个所有者在记录中对其名称的NOT NULL条目数。 最后一列只是计算每个所有者拥有的记录数

where customertype = 'Customer

DROP TABLE mytable;
CREATE TABLE mytable(
owneridname  VARCHAR(12) NOT NULL PRIMARY KEY
,cyber        VARCHAR(14) NOT NULL
,encryption   VARCHAR(7) NOT NULL
,firewall     VARCHAR(19) NOT NULL
,pcidss       VARCHAR(4) NOT NULL
,asvscanner   VARCHAR(20) NOT NULL
,pentesting   VARCHAR(10) NOT NULL
,phishin      VARCHAR(19) NOT NULL
,scanner      VARCHAR(10) NOT NULL
,twofactor    VARCHAR(6) NOT NULL
,customertype VARCHAR(8) NOT NULL
);
     INSERT INTO mytable   (owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Dave',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRM Support',NULL,NULL,NULL,'No','-- Not Applicable --',NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Dave',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Daniel',NULL,NULL,'WatchGuard','No','-- Not Applicable --',NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Joey',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Daniel',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,'No Opportunity',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Kenny',NULL,NULL,'WatchGuard',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Daniel',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Matt',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE','In Action',NULL,NULL,'No','-- Not Applicable --','Yes',NULL,'AppCheck',NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRM Guest 01',NULL,NULL,NULL,'No','-- Not  Applicable --','Yes',NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Joey',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRM Guest 01',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Daniel',NULL,NULL,'WatchGuard',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Joey',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,'WatchGuard',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Luke','Not Interested',NULL,'WatchGuard','No','-- Not Applicable --','No','No - Not Interested','In Process','#NAME?','Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Kenny',NULL,'Other',NULL,NULL,NULL,'Yes',NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Joey',NULL,'None','WatchGuard','No','-- Not Applicable --','No',NULL,'None',NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Matt',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Asa',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,'WatchGuard',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Daniel',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Daniel',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Ryan',NULL,NULL,'Juniper','No','-- Not Applicable --','Yes',NULL,'None','#NAME?','Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Daniel',NULL,NULL,'Cisco',NULL,NULL,'Yes',NULL,'AppCheck',NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Adam',NULL,NULL,NULL,'No',NULL,'Yes',NULL,'AppCheck',NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Matt',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Gareth','Not Interested','Other',NULL,'Yes',NULL,'Yes',NULL,NULL,'#NAME?','Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Gareth',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Kenny',NULL,NULL,NULL,'No','-- Not Applicable --','Yes',NULL,'None',NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Matt',NULL,NULL,'WatchGuard',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Adam',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Ryan',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Ryan',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Scott',NULL,NULL,'WatchGuard',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Luke','Not Interested',NULL,'No Opportunity','No','-- Not Applicable --','No','No - Not Interested','In Process','#NAME?','Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Gareth',NULL,NULL,NULL,'Yes',NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('James',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Scott',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Dave','Not Interested',NULL,'Cisco','Yes','-- Not Applicable --','Yes',NULL,'Nessus',NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Matt',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Matt',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,'Yes',NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Gareth','Not Interested','None','WatchGuard','No','-- Not Applicable --','No','No - Not Interested',NULL,'#NAME?','Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,'SonicWALL',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Dave',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Adam','In Action',NULL,'Palo Alto','Yes',NULL,'Yes',NULL,'AppCheck','#NAME?','Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Ryan',NULL,NULL,'WatchGuard',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRM Support',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Daniel',NULL,'BeCrypt','Stonesoft StoneGate','Yes',NULL,'Yes',NULL,'None','VASCO','Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Lisa Copley',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'#NAME?','Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,'WatchGuard','No','-- Not Applicable --','Yes',NULL,'None','RSA','Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,'Check Point',NULL,NULL,'Yes',NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Adam',NULL,'PGP','WatchGuard','No','-- Not Applicable --','No',NULL,'None',NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Ryan',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Joey',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Stephanie',NULL,NULL,NULL,NULL,NULL,'No',NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Matt',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Matt',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRM Support',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Matt',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,'No Opportunity',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRM Support',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Gareth','Not Interested',NULL,'Sophos','Yes',NULL,'Yes','No - Not Interested',NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Alex Evans',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,'Microsoft ISA',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Kenny',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Matt',NULL,NULL,'WatchGuard',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRM Support',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Gareth','Not Interested',NULL,'WatchGuard','No','-- Not Applicable --','In Process',NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Matt',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Daniel',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRM Support',NULL,NULL,NULL,'Yes',NULL,'Yes',NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Ryan',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Ryan',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE','Unkown',NULL,'DrayTek',NULL,NULL,'No',NULL,'None','#NAME?','Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,'Sophos',NULL,NULL,NULL,NULL,NULL,NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRMSERVICE',NULL,NULL,'SonicWALL',NULL,NULL,NULL,NULL,'Other','#NAME?','Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('Emma',NULL,NULL,NULL,'Yes',NULL,'Yes',NULL,'Nessus',NULL,'Customer');
    INSERT INTO mytable(owneridname,cyber,encryption,firewall,pcidss,asvscanner,pentesting,phishin,scanner,twofactor,customertype) VALUES ('CRM Support',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Customer');

任何想法都会非常受欢迎。

1 个答案:

答案 0 :(得分:0)

这样的事情应该有效:

select getdate(), owneridname, count(cyber), count(encryption),
count(1) totalentries
from sourcedata
group by owneridname

我仅以网络和加密为例,但您也可以完成其他区域的计数