SELECT FATURA.LOGICALREF AS REF, FATURA.FICHENO AS [FATURA NO],
CARI.CODE AS [CARİ KODU], CARI.DEFINITION_ AS [CARİ ADI],
FATURA.DATE_ AS [FATURA TARİHİ], SUM(SATIR.AMOUNT) AS [SATILAN ADET],
ROUND(SUM(SATIR.OUTCOST * SATIR.AMOUNT), 2) AS MALİYET,
ROUND(SUM(SATIR.LINENET), 2) AS NETSATIS,
ROUND(SUM(SATIR.LINENET) - SUM(SATIR.OUTCOST * SATIR.AMOUNT), 2) AS KAR,
ROUND((ROUND(SUM(SATIR.LINENET), 2) /
ROUND(SUM(CASE WHEN SATIR.OUTCOST > 0 THEN SATIR.OUTCOST * SATIR.AMOUNT ELSE 1 END), 2)
- 1) * 100, 2) AS YÜZDE, PLASIYER.DEFINITION_ AS Plasiyer_ADI, LG_001_ITEMS.CODE, LG_001_ITEMS.NAME, PLASIYER.FIRMNR
FROM LG_212_01_INVOICE AS FATURA INNER JOIN
LG_212_01_STLINE AS SATIR ON SATIR.INVOICEREF = FATURA.LOGICALREF INNER JOIN
LG_212_CLCARD AS CARI ON CARI.LOGICALREF = FATURA.CLIENTREF INNER JOIN
LG_SLSMAN AS PLASIYER ON PLASIYER.LOGICALREF = FATURA.SALESMANREF INNER JOIN
LG_212_ITEMS ON SATIR.STOCKREF = LG_001_ITEMS.LOGICALREF
WHERE (FATURA.TRCODE = 8 ) AND (FATURA.DATE_ BETWEEN
CONVERT(DATETIME, '2012-01-01 00:00:00', 102) AND
CONVERT(DATETIME, '2012-12-31 00:00:00', 102))
AND (SATIR.STOCKREF > 0) AND (FATURA.CANCELLED = 0)
GROUP BY FATURA.LOGICALREF, FATURA.FICHENO, CARI.CODE, CARI.DEFINITION_,
FATURA.DATE_, PLASIYER.DEFINITION_, LG_001_ITEMS.CODE,
LG_212_ITEMS.NAME, PLASIYER.FIRMNR
HAVING (PLASIYER.FIRMNR = 212)
ORDER BY LG_001_ITEMS.CODE
-- Bunu deneyin, Satış elemanları ortak olduğundan, Satış elemanları için firma kodu filitresi kullandım.