I am using MySQL 5.5. I have a query which returns results like this
quantity| maxPrice| minPrice |avgPrice| counts
"10" "23.50" "23.50" "23.500000" "1"
"15" "15.75" "15.75" "15.750000" "1"
"23" "100.71" "100.71" "100.710000" "1"
"25" "210.00" "200.00" "205.000000" "2"
now from this data I want to extract the maximum quantity tuple and sum of all counts… so that result would look like this
quantity| maxPrice| minPrice |avgPrice| counts
"25" "210.00" "200.00" "205.000000" 5
how do I write query for this?
Use
ORDER BY quantity DESCandLIMIT 1to extract the tuple. Surround your query with another select and useSUM(counts) AS countsfor the total.Example:
Replace
SELECT * FROM mytablewith your real query.