我使用以下查詢來按記錄選擇組。每週報告選擇來自SQL組的查詢
SELECT YEARWEEK(dtentered) week, sum(leftcount) as lct, sum(rightcount) as rct FROM `dailycount` WHERE paid='1' and regid='SF00033200712' GROUP BY YEARWEEK(dtentered) "
但我只收到本週的報告。我想顯示所有的每週報告。我不知道如何改變這一點。
CREATE TABLE IF NOT EXISTS `dailycount` (
`countid` int(11) NOT NULL AUTO_INCREMENT,
`regid` varchar(13) NOT NULL,
`paid` int(11) NOT NULL,
`dtentered` date NOT NULL,
`leftcount` int(11) NOT NULL,
`rightcount` int(11) NOT NULL,
`carryleft` int(11) NOT NULL,
`carryright` int(11) NOT NULL,
`total_pairs` int(11) NOT NULL,
`gross` int(11) NOT NULL,
`service` decimal(19,2) NOT NULL DEFAULT '0.00',
`net` decimal(19,2) NOT NULL DEFAULT '0.00',
PRIMARY KEY (`countid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=33 ;
INSERT INTO `dailycount` (`countid`, `regid`, `paid`, `dtentered`, `leftcount`, `rightcount`, `carryleft`, `carryright`, `total_pairs`, `gross`, `service`, `net`) VALUES
(6, 'SF00033200712', 1, '2013-05-14', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(5, 'SF00034140513', 1, '2013-05-14', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(4, 'SF00033200712', 1, '2013-05-14', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(7, 'SF00035140513', 1, '2013-05-14', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(8, 'SF00034140513', 1, '2013-05-14', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(9, 'SF00033200712', 1, '2013-05-14', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(10, 'SF00033200712', 1, '2013-05-14', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(11, 'SF00034140513', 1, '2013-05-14', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(12, 'SF00033200712', 1, '2013-05-14', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(13, 'SF00037140513', 1, '2013-05-14', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(14, 'SF00033200712', 1, '2013-05-14', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(15, 'SF00039140513', 1, '2013-05-14', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(16, 'SF00037140513', 1, '2013-05-14', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(17, 'SF00033200712', 1, '2013-05-14', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(18, 'SF00037140513', 1, '2013-05-14', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(19, 'SF00033200712', 1, '2013-05-14', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(20, 'SF00041140513', 1, '2013-05-14', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(21, 'SF00037140513', 1, '2013-05-14', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(22, 'SF00033200712', 1, '2013-05-14', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(23, 'SF00039140513', 1, '2013-05-14', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(24, 'SF00037140513', 1, '2013-05-14', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(25, 'SF00033200712', 1, '2013-05-14', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(26, 'SF00041140513', 1, '2013-05-22', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(27, 'SF00037140513', 1, '2013-05-22', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(28, 'SF00033200712', 1, '2013-05-22', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(29, 'SF00042140513', 1, '2013-05-15', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(30, 'SF00041140513', 1, '2013-05-15', 0, 1, 0, 0, 0, 0, 0.00, 0.00),
(31, 'SF00037140513', 1, '2013-05-15', 1, 0, 0, 0, 0, 0, 0.00, 0.00),
(32, 'SF00033200712', 1, '2013-05-15', 1, 0, 0, 0, 0, 0, 0.00, 0.00);
我想你可以刪除[PHP]和[phpMyAdmin的]標籤,問題是直接有關SQL。如下 – Voitcus
更改SQL:SELECT SUM(leftcount)作爲YEARWEEK(dtentered),LCT,總和(rightcount)作爲RCT FROM'dailycount' WHERE和付費= '1' 和REGID = 'SF00033200712' 基團由YEARWEEK(dtentered); –