SELECT
putri_product_type.product_type_name,
Sum(putri_order_all.product_price) AS Sum,
Count(putri_order_all.product_type) AS Count
FROM
putri_product_type
LEFT JOIN putri_order_all ON putri_order_all.product_type = putri_product_type.product_type_id
GROUP BY
putri_product_type.product_type_id
ORDER BY
count DESC
SELECT
putri_product_type.product_type_name,
Sum(putri_order_all.product_price) AS Sum,
Count(putri_order_all.product_type) AS Count
FROM
putri_product_type
LEFT JOIN putri_order_all ON putri_order_all.product_type = putri_product_type.product_type_id
WHERE
putri_order_all.date_order BETWEEN "2020-07-01" AND "2020-07-31"
GROUP BY
putri_product_type.product_type_id
ORDER BY
count DESC
select * from (
select m.id, m.name, sum( coalesce(s.amt,0)) as amount, sum(coalesce(s.qty, 0)) as quatity
from table_stock_name as m
left join tb_sale as s
on s.id = m.id and s.sale_date between x_first_date and x_last_date
group by m.id
) as t
order by t.amount desc
select * from (
select m.id, m.name, sum( coalesce(s.amt,0)) as amount, sum(coalesce(s.qty, 0)) as quatity
from table_stock_name as m
left join tb_sale as s
on s.id = m.id and s.sale_date between x_first_date and x_last_date
group by m.id
) as t
order by t.amount desc
sum(coalesce(s.qty, 0)) as quatity ค่านี้ จะ Sum ครับ แต่ผมต้องการ Count จำนวนชิ้นครับ ไม่ทราบว่าต้องปรับอย่างไรครับ