php - SQL most popular -


I have a mysql table with items in relation to their order.


  Make database if 'sqltest` does not exist; USE `sqltest`; If the testadata exists then drop table; Table `testdata` (` orderID` varchar (10) default zero, `itemID` varchar (10) default zero,` qtyOrdered` integer (10) default zero, `sellingPrice` decimals (10,2) default zero) create INSERT INTO `Testdata` (` orderID`, `itemID`,` qtyOrdered`, `sellingPrice`) values ​​('1', 'one', 1, '7.00'), ('1', 'b', 2, '8.00 ',' ('1', 'C', 3, '3.00'), ('2', 'A', 1, '7.00'), ('2', 'C', 4, '3.00') ;  

Objective result:

A = (1 + 1) 2

b = 2

C = (2 + 4) 6 & lt; -? The most popular


How can I add all the quantities to each item and the highest one result

It should be quite straight forward but I'm new to SQL and I This one can not work out: S

The solution needs to be mysql and php or

I think there is something needed to do. Like a temporary matching value for each item ID, but it seems that it can be dirty with too many items. Answer:

(thanks nuqqsa)

  Item ID, SUM (qtyOrdered) Item IDID by total DESC limit Total 1 by TestData Group;  

itemprop = "text">

how about this:

  select ItemID, qtyOrdered Total DESC by Item IDID; Total from TestData Group;  

Comments