บทความ > SQL

[SQL] Group data from right join transaction table Turn Back

เมื่อ 2018-02-22 17:41:33

SELECT z.delivery_type, IF(dt.detail IS NULL or dt.detail = '', pt.status_desc, dt.detail) as DT, count(*) CNT, z.price FROM
(
SELECT d.pack_type, d.delivery_type, d.price
FROM postmail_header h 
RIGHT JOIN postmail_detail d on d.post_hid=h.post_hid 
WHERE h.doc_status=3 and d.delivery_type IN (18,19,20)
) z
LEFT JOIN mst_extra_charge dt on dt.extra_id=z.delivery_type 
LEFT JOIN mst_status_type pt on pt.id=z.pack_type 
GROUP BY z.pack_type, z.delivery_type, z.price
Turn Back

Automotive ดูทั้งหมด

IT Update ดูทั้งหมด