Ben onların sırasına göre öğeleri ile bir mysql tablo var.
CREATE DATABASE IF NOT EXISTS `sqltest`;
USE `sqltest`;
DROP TABLE IF EXISTS `testdata`;
CREATE TABLE `testdata` (
`orderID` varchar(10) DEFAULT NULL,
`itemID` varchar(10) DEFAULT NULL,
`qtyOrdered` int(10) DEFAULT NULL,
`sellingPrice` decimal(10,2) DEFAULT NULL
)
INSERT INTO `testdata`(`orderID`,`itemID`,`qtyOrdered`,`sellingPrice`)
values ('1','a',1,'7.00'),('1','b',2,'8.00'),('1','c',3,'3.00'),('2','a',1,'7.00'),('2','c',4,'3.00');
Amaçlanan Sonuç:
A = (1 +1) 2
B = 2
C = (2 +4) 6 <- en popüler
How do I add up all the qty's for each item and result the highest one?
Bu ileri oldukça dar olmalı ama ben SQL yeni ve ben bu bir işe değil: S
Çözüm mysql ve php veya olması gerekir.
I guess there needs to be some sort of temporary tally variable for each item ID, but that seems like it could get messy with too many items.
ANSWER:
(Teşekkürler nuqqsa)
SELECT itemID, SUM(qtyOrdered) AS total FROM testdata GROUP BY itemID ORDER BY total DESC LIMIT 1;