所以我有一个查询,将计数细分为2列。查询如下:
SELECT `Location`, `Model Name`, Count
FROM (
SELECT IF(`Location` = @Prev, NULL, `Location`) AS 'Location',
`Model Name`,
Count,
@Prev := `Location`
FROM (SELECT `locations`.`location_name` AS 'Location',
`inventory`.`equip_model` AS 'Model Name',
count(`inventory`.`equip_model`) AS 'Count'
FROM mod_inventory_data AS `inventory`
LEFT JOIN mod_locations_rooms AS `rooms` ON `rooms`.room_id = `inventory`.room_id
WHERE inventory.equip_model LIKE '%optiplex%'
GROUP BY `Location`, `Model Name`) AS subq
CROSS JOIN (SELECT @Prev := NULL) AS init
) AS subq2
上面的查询将产生如下输出:
location 1 optiplex 745 24
optiplex 755 18
optiplex 780 30
location 2 optiplex 745 15
optiplex 755 22
optiplex 780 25
有没有办法修改它给我这样的东西:
location 1 optiplex 745 24
optiplex 755 18
optiplex 780 30
TOTAL: 72
location 2 optiplex 745 15
optiplex 755 22
optiplex 780 25
TOTAL: 62
GRAND TOTAL: 134
非常感谢任何帮助。
Dan B。