REPORTFORM;SA16.frf
TITLE;วิเคราะห์ขาย ยอดขายสินค้าทั้งปี
SQL;SELECT
SQL;INVCARD.ID,
SQL;INVMST.XDESC,
SQL;SUM(INVCARD.SALEPURAMT) AS SALEPURAMT,
SQL;SUM(IF(MONTH(INVCARD.DATEDOC)=1,INVCARD.SALEPURAMT,0)) AS MTH1,
SQL;SUM(IF(MONTH(INVCARD.DATEDOC)=2,INVCARD.SALEPURAMT,0)) AS MTH2,
SQL;SUM(IF(MONTH(INVCARD.DATEDOC)=3,INVCARD.SALEPURAMT,0)) AS MTH3,
SQL;SUM(IF(MONTH(INVCARD.DATEDOC)=4,INVCARD.SALEPURAMT,0)) AS MTH4,
SQL;SUM(IF(MONTH(INVCARD.DATEDOC)=5,INVCARD.SALEPURAMT,0)) AS MTH5,
SQL;SUM(IF(MONTH(INVCARD.DATEDOC)=6,INVCARD.SALEPURAMT,0)) AS MTH6,
SQL;SUM(IF(MONTH(INVCARD.DATEDOC)=7,INVCARD.SALEPURAMT,0)) AS MTH7,
SQL;SUM(IF(MONTH(INVCARD.DATEDOC)=8,INVCARD.SALEPURAMT,0)) AS MTH8,
SQL;SUM(IF(MONTH(INVCARD.DATEDOC)=9,INVCARD.SALEPURAMT,0)) AS MTH9,
SQL;SUM(IF(MONTH(INVCARD.DATEDOC)=10,INVCARD.SALEPURAMT,0)) AS MTH10,
SQL;SUM(IF(MONTH(INVCARD.DATEDOC)=11,INVCARD.SALEPURAMT,0)) AS MTH11,
SQL;SUM(IF(MONTH(INVCARD.DATEDOC)=12,INVCARD.SALEPURAMT,0)) AS MTH12
SQL;FROM INVCARD 
SQL;LEFT JOIN INVMST ON INVCARD.ID = INVMST.ID
SQL;WHERE (LEFT(INVCARD.DOCNO,2) = "IV" OR LEFT(INVCARD.DOCNO,2) = "RI")
SQL;GROUP BY 1,2
SQL;ORDER BY INVCARD.ID
CONDITION;ตั้งแต่วันที่~INVCARD.DATEDOC~Date~2~~
CONDITION;ตั้งแต่รหัสสินค้า ~INVCARD.ID~Chr~2~SELECT ID FROM INVMST~INV
EXCELSQL;SELECT
EXCELSQL;INVCARD.ID AS "รหัสสินค้า",
EXCELSQL;INVMST.XDESC AS "รายละเอียดสินค้า",
EXCELSQL;SUM(INVCARD.SALEPURAMT) AS SALEPURAMT,
EXCELSQL;SUM(IF(MONTH(INVCARD.DATEDOC)=1,INVCARD.SALEPURAMT,0)) AS MTH1,
EXCELSQL;SUM(IF(MONTH(INVCARD.DATEDOC)=2,INVCARD.SALEPURAMT,0)) AS MTH2,
EXCELSQL;SUM(IF(MONTH(INVCARD.DATEDOC)=3,INVCARD.SALEPURAMT,0)) AS MTH3,
EXCELSQL;SUM(IF(MONTH(INVCARD.DATEDOC)=4,INVCARD.SALEPURAMT,0)) AS MTH4,
EXCELSQL;SUM(IF(MONTH(INVCARD.DATEDOC)=5,INVCARD.SALEPURAMT,0)) AS MTH5,
EXCELSQL;SUM(IF(MONTH(INVCARD.DATEDOC)=6,INVCARD.SALEPURAMT,0)) AS MTH6,
EXCELSQL;SUM(IF(MONTH(INVCARD.DATEDOC)=7,INVCARD.SALEPURAMT,0)) AS MTH7,
EXCELSQL;SUM(IF(MONTH(INVCARD.DATEDOC)=8,INVCARD.SALEPURAMT,0)) AS MTH8,
EXCELSQL;SUM(IF(MONTH(INVCARD.DATEDOC)=9,INVCARD.SALEPURAMT,0)) AS MTH9,
EXCELSQL;SUM(IF(MONTH(INVCARD.DATEDOC)=10,INVCARD.SALEPURAMT,0)) AS MTH10,
EXCELSQL;SUM(IF(MONTH(INVCARD.DATEDOC)=11,INVCARD.SALEPURAMT,0)) AS MTH11,
EXCELSQL;SUM(IF(MONTH(INVCARD.DATEDOC)=12,INVCARD.SALEPURAMT,0)) AS MTH12
EXCELSQL;FROM INVCARD 
EXCELSQL;LEFT JOIN INVMST ON INVCARD.ID = INVMST.ID
EXCELSQL;WHERE (LEFT(INVCARD.DOCNO,2) = "IV" OR LEFT(INVCARD.DOCNO,2) = "RI")
EXCELSQL;GROUP BY 1,2
EXCELSQL;ORDER BY INVCARD.ID
