我有一个名为tblItemReviewItems的表,我必须为给定日期的每个UserId选择10%的ItemReviewId样本。 这是表脚本和一些示例数据:
CREATE TABLE tblItemReviewItems(
ItemReviewId INTEGER NOT NULL PRIMARY KEY
,UserId VARCHAR(50) NOT NULL
,ReviewDate DATE NOT NULL
,Deleted VARCHAR(10) NOT NULL
,Audited VARCHAR(10) NOT NULL
);
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425282,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425291,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425299,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425304,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425311,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425324,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425333,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425358,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425423,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425443,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425482,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425547,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425580,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425899,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425921,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16426037,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16426239,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16426257,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16426787,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427205,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427428,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427465,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427506,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427545,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427596,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427615,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427841,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427860,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427908,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428038,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428200,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428665,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429222,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429240,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429254,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429275,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429283,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429642,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429653,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429658,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429671,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429691,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429706,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429718,'jdoe1','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427072,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427221,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427299,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427628,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428359,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428988,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429003,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429346,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430270,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431587,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16432199,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16433774,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16434065,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16435062,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16435667,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16435702,'jdoe1','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425351,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425396,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425472,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16426042,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16426260,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427379,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427497,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427553,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427568,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427575,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427595,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427613,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427653,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427688,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427698,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427877,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428006,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428031,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428353,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428375,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428827,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428883,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428929,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429004,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429121,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429138,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429624,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429647,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429776,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429837,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429890,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430032,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430061,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430100,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430158,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430173,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430223,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430311,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430357,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430440,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430471,'jdoe2','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425491,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425629,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425722,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16426266,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427719,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427957,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428401,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429028,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429146,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431275,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431558,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16432351,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16432521,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16434592,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16434822,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16435461,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16435562,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16435658,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16435694,'jdoe2','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425249,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425393,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425513,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425575,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425604,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425906,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427509,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428876,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428889,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428937,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428966,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16428977,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429001,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429036,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429062,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429096,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429118,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429809,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429944,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429984,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430038,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430048,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430115,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430140,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430189,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430339,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430368,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430420,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430439,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430467,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430651,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430656,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430663,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430842,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430846,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430876,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431068,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431080,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431100,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431475,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431517,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431545,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431572,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431616,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431753,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431792,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431803,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431812,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431833,'jdoe3','7/1/2017','Yes','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16425929,'jdoe3','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16427532,'jdoe3','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429660,'jdoe3','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16429819,'jdoe3','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16430204,'jdoe3','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16431287,'jdoe3','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16432004,'jdoe3','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16434233,'jdoe3','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16434999,'jdoe3','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16435056,'jdoe3','7/1/2017','No','No');
INSERT INTO tblItemReviewItems(ItemReviewId,UserId,ReviewDate,Deleted,Audited) VALUES (16435798,'jdoe3','7/1/2017','No','No');
ALTER PROC [dbo].[spPickSample]
AS
BEGIN
DECLARE @Nos INT = (SELECT COUNT (*) FROM tblItemReviewItems WHERE Deleted='No' and UserId='jdoe1')
DECLARE @Yes INT = (SELECT COUNT (*) FROM tblItemReviewItems WHERE Deleted='Yes' and UserId='jdoe1')
DECLARE @Samplepct FLOAT =(.05*(@Nos + @Yes)) / @Nos*100
DECLARE @Percentage AS INT = @Samplepct
SELECT
TOP (@Percentage) PERCENT *
FROM
tblItemReviewItems
WHERE
Deleted='No' AND UserId='jdoe1'
ORDER BY
NEWID()
END
5%的人口应来自Deleted(No),5%的人口应来自Deleted(是)。
人口:
+-------------+----+-----+-------------+
| UserId | No | Yes | Grand Total |
+-------------+----+-----+-------------+
| jdoe1 | 16 | 44 | 60 |
| jdoe2 | 19 | 41 | 60 |
| jdoe3 | 11 | 49 | 60 |
| Grand Total | 46 | 134 | 180 |
+-------------+----+-----+-------------+
目标样本:
+-------------+----+-----+-------------+
| UserId | No | Yes | Grand Total |
+-------------+----+-----+-------------+
| jdoe1 | 3 | 3 | 6 |
| jdoe2 | 3 | 3 | 6 |
| jdoe3 | 3 | 3 | 6 |
| Grand Total | 9 | 9 | 18 |
+-------------+----+-----+-------------+
这是我想要获得的:
+--------------+--------+------------+---------+---------+
| ItemReviewId | UserId | ReviewDate | Deleted | Audited |
+--------------+--------+------------+---------+---------+
| 16427072 | jdoe1 | 7/1/2017 | No | Check |
| 16428359 | jdoe1 | 7/1/2017 | No | Check |
| 16429003 | jdoe1 | 7/1/2017 | No | Check |
| 16429222 | jdoe1 | 7/1/2017 | Yes | Check |
| 16428665 | jdoe1 | 7/1/2017 | Yes | Check |
| 16425311 | jdoe1 | 7/1/2017 | Yes | Check |
| 16426266 | jdoe2 | 7/1/2017 | No | Check |
| 16432521 | jdoe2 | 7/1/2017 | No | Check |
| 16435694 | jdoe2 | 7/1/2017 | No | Check |
| 16427379 | jdoe2 | 7/1/2017 | Yes | Check |
| 16427568 | jdoe2 | 7/1/2017 | Yes | Check |
| 16427877 | jdoe2 | 7/1/2017 | Yes | Check |
| 16427532 | jdoe3 | 7/1/2017 | No | Check |
| 16435798 | jdoe3 | 7/1/2017 | No | Check |
| 16429660 | jdoe3 | 7/1/2017 | No | Check |
| 16430140 | jdoe3 | 7/1/2017 | Yes | Check |
| 16430339 | jdoe3 | 7/1/2017 | Yes | Check |
| 16428937 | jdoe3 | 7/1/2017 | Yes | Check |
+--------------+--------+------------+---------+---------+
以下是我的尝试:
ALTER PROC [dbo].[PickSample]
(
@ReviewDate AS DATETIME
,@UserId AS NVARCHAR(50)
)
AS
BEGIN
DECLARE @tempDashboard table
(
ItemReviewId VarChar(50)
,UserId VarChar(50)
,ReviewDate Datetime
,Deleted varchar(10)
,Audited varchar(10)
)
DECLARE @Nos INT = (SELECT COUNT (*) FROM tblItemReviewItems WHERE Deleted='No' AND ReviewDate=@ReviewDate AND UserId=@UserId)
DECLARE @Yes INT = (SELECT COUNT (*) FROM tblItemReviewItems WHERE Deleted='Yes' AND ReviewDate=@ReviewDate AND UserId=@UserId)
DECLARE @Samplepct FLOAT =(.05*(@Nos + @Yes)) / @Nos*100
DECLARE @Percentage AS INT = @Samplepct
INSERT INTO @tempDashboard (ItemReviewId, UserId, ReviewDate, Deleted, Audited)
SELECT
TOP (@Percentage) PERCENT ItemReviewId, UserId, ReviewDate, Deleted, Audited
FROM
tblItemReviewItems
WHERE
Deleted='No' AND ReviewDate=@ReviewDate AND UserId=@UserId
ORDER BY
NEWID()
DECLARE @Nos2 INT = (SELECT COUNT (*) FROM tblItemReviewItems WHERE Deleted='No' AND ReviewDate=@ReviewDate AND UserId=@UserId)
DECLARE @Yes2 INT = (SELECT COUNT (*) FROM tblItemReviewItems WHERE Deleted='Yes' AND ReviewDate=@ReviewDate AND UserId=@UserId)
DECLARE @Samplepct2 FLOAT =(.05*(@Nos2 + @Yes2)) / @Yes2*100
DECLARE @Percentage2 AS INT = @Samplepct2
INSERT INTO @tempDashboard (ItemReviewId, UserId, ReviewDate, Deleted, Audited)
SELECT
TOP (@Percentage2) PERCENT ItemReviewId, UserId, ReviewDate, Deleted, Audited
FROM
tblItemReviewItems
WHERE
Deleted='Yes' AND ReviewDate=@ReviewDate AND UserId=@UserId
ORDER BY
NEWID()
UPDATE a
SET Audited='Check'
FROM tblItemReviewItems AS a
INNER JOIN @tempDashboard AS b
ON b.ItemReviewId=a.ItemReviewId
END
我必须为每个用户运行存储过程。通常每天大约有200个用户。所以我必须在一天内运行存储过程200次。我如何一次性实现这一目标?
答案 0 :(得分:0)
以下是执行此操作的方法 - 将行选择到临时表中。如果您有主键,则只需选择主键。如果您没有主键,请选择足够的列以使组合具有唯一性。在临时表中获得所需的行后,与该临时表连接并使用您想要的值更新原始表中的那些行。如果您不想对随后选择的行执行任何操作,则可以在使用正确的where子句进行选择后实际更新行。
答案 1 :(得分:0)
类似的东西:
ALTER PROC [dbo].[spPickSample]
AS
BEGIN
DECLARE @Nos INT = (SELECT COUNT (*) FROM tblItemReviewItems WHERE Deleted='No' and UserId='jdoe1')
DECLARE @Yes INT = (SELECT COUNT (*) FROM tblItemReviewItems WHERE Deleted='Yes' and UserId='jdoe1')
DECLARE @Samplepct FLOAT =(.05*(@Nos + @Yes)) / @Nos*100
DECLARE @Percentage AS INT = @Samplepct
DECLARE @temptable table (ItemReviewId nvarchar(50))
INSERT into @temptable
SELECT
TOP (@Percentage) PERCENT ItemReviewId
FROM
tblItemReviewItems
WHERE
Deleted='No' AND UserId='jdoe1'
Update t set Audited="Check"
from tblItemReviewItems t
where ItemReviewId in (Select ItemReviewId from @temptable)
Select * from tblItemReviewItems
where ItemReviewId in (Select ItemReviewId from @temptable)
END
假设您的用户位于名为' [users]'的表中。然后你可以用这种方式循环游标:
DECLARE @userid nvarchar(50)
DECLARE db_cursor CURSOR FOR
SELECT userid
FROM [users]
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @userid
WHILE @@FETCH_STATUS = 0
BEGIN
exec dbo.PickSample '2017-07-01',@userid
FETCH NEXT FROM db_cursor INTO @userid
END
请注意,我对审核日期进行了硬编码,但是您可能需要根据自己的具体情况调整照片