select brand.Brand_name,model.model_name,product.salecost,sale.sale_date,COUNT(Model.model_id)
from saledetail
, sale
, product
, model
, brand
where saledetail.sale_id = sale.sale_id
and saledetail.imei = product.imei
and product.model_id = model.model_id
and model.brand_id = brand.brand_id
group by model.model_id
order by COUNT(Model.model_id)
select sale.sale_date,SUM(product.salecost) as sumcost,model.model_name,brand.Brand_name
from ((((saledetail LEFT JOIN sale ON saledetail.sale_id = sale.sale_id)
Left JOIN product ON saledetail.imei = product.imei)
Left JOIN model ON product.model_id = model.model_id)
Left JOIN brand ON model.brand_id = brand.brand_id)
GROUP BY model.model_name
order by sale.sale_date ASC , brand.Brand_name asc
ฟิลด์อื่นก็ใช้ min หรือ max เอาค่ะ ถ้าไม่อยาก group by แต่ถ้าไม่ใช้ min,max ต้องgroup by ให้ครบทุกฟิลด์ค่ะยกเว้นฟิลด์ที่ sum จากโค้ดคุณ group by แค่ modelname