1)get the tablse schema;
describe sales_flat_order;
show columns from sales_flat_order;
2)write the SQL
selecttt.customer_group_code,tt.name,sum(tt.total_qty_ordered)from
(selectc.customer_group_code,t.coupon_code,t.total_qty_ordered,t.grand_total,s.name
from sales_flat_order t inner join sales_flat_order_item s ont.entity_id = s.order_id inner join customer_group c ont.customer_group_id = c.customer_group_id) tt group bytt.customer_group_code,tt.name
3) write the codes;
$resource = Mage::getSingleton('core/resource');
$connection = $resource->getConnection('core_read');
$sql = " above SQL";
$results = $connection->fetchAll($sql);