// -----------------------------------------------------------------------------------------------------------------------
// SELECT requests test
//
// The requests must have the following format:
// #begin
// <SELECT request>
// #end
// <isValid flag>: true if this request is valid
//
// If the request is valid:
// <selected columns concerning by the select clause prefixed by the table>: for example: my_table.id
// <selected table concerning by the from clause, eventually suffixed by an alias>: for example: my_table, my_table.my_alias, my_table
// <selected columns concerning by the where clause prefixed by the table>: for example: my_table.id
// <request type>: either CACHEABLE, UNCACHEABLE or UNIQUE_CACHEABLE
//
// If the request is not valid:
// <error message>
//
// do not add empty line between the lines defining a test
// line beginning by a // are ignored except in a test
// -----------------------------------------------------------------------------------------------------------------------

//1
#begin
WITH TEST_YANIT_DATA AS
(SELECT
IK.KURS.F_EGITIM_KURUM_NO,
IK.KURS.F_EGITIM_YER_NO,
IK.KURS.F_EGITMEN_NO,
IK.KURS.F_EGITIM_KOD,
IK.KURS.NO AS F_KURS_NO,
IK.KURS_KATILIM.NO AS F_KURS_KATILIM_NO,
IK.TEST_SORU_YANIT.F_TEST_BOLUM_KOD,
IK.TEST_YANIT.NO AS TEST_YANIT_NO,
IK.TEST_SORU_SECENEK.PUAN

FROM
IK.TEST_YANIT
LEFT OUTER JOIN
IK.TEST_SORU_YANIT
ON IK.TEST_YANIT.NO=IK.TEST_SORU_YANIT.F_TEST_YANIT_NO

AND IK.TEST_YANIT.F_FIRMA_KOD=IK.TEST_SORU_YANIT.F_FIRMA_KOD
AND IK.TEST_YANIT.F_TEST_NO=IK.TEST_SORU_YANIT.F_TEST_NO

LEFT OUTER JOIN
IK.TEST_SORU_SECENEK
ON IK.TEST_SORU_YANIT.F_YANITLANAN_SECENEK_NO= IK.TEST_SORU_SECENEK.NO

LEFT OUTER JOIN
IK.KURS
ON IK.TEST_YANIT.F_KURS_NO=IK.KURS.NO

AND IK.TEST_YANIT.F_FIRMA_KOD=IK.KURS.F_FIRMA_KOD

LEFT OUTER JOIN
IK.KURS_KATILIM
ON IK.TEST_YANIT.F_KURS_KATILIM_NO=IK.KURS_KATILIM.NO

AND IK.TEST_YANIT.F_FIRMA_KOD=IK.KURS_KATILIM.F_FIRMA_KOD

WHERE
IK.KURS.F_EGITIM_KURUM_NO IS NOT NULL

AND IK.KURS.IPTAL='0'
AND IK.KURS.ONAY='1'
AND IK.KURS_KATILIM.ONAY='1'
),

EGITIM_KURUM_DATA AS
(SELECT
F_EGITIM_KURUM_NO,
TEST_YANIT_NO,
SUM(PUAN) AS YANIT_PUAN

FROM
TEST_YANIT_DATA
WHERE
F_EGITIM_KURUM_NO IS NOT NULL

GROUP BY
F_EGITIM_KURUM_NO,
TEST_YANIT_NO
),

EGITIM_YER_DATA AS
(SELECT
F_EGITIM_YER_NO,
TEST_YANIT_NO,
SUM(PUAN) AS YANIT_PUAN

FROM
TEST_YANIT_DATA
WHERE
F_EGITIM_YER_NO IS NOT NULL
AND F_TEST_BOLUM_KOD='d'

GROUP BY
F_EGITIM_YER_NO,
TEST_YANIT_NO
),

EGITMEN_DATA AS
(SELECT
F_EGITMEN_NO,
TEST_YANIT_NO,
SUM(PUAN) AS YANIT_PUAN

FROM
TEST_YANIT_DATA
WHERE
F_EGITMEN_NO IS NOT NULL
AND F_TEST_BOLUM_KOD='b'

GROUP BY
F_EGITMEN_NO,
TEST_YANIT_NO
),

EGITIM_DATA AS
(SELECT
F_EGITIM_KOD,
TEST_YANIT_NO,
SUM(PUAN) AS YANIT_PUAN

FROM
TEST_YANIT_DATA
WHERE
F_EGITIM_KOD IS NOT NULL

GROUP BY
F_EGITIM_KOD,
TEST_YANIT_NO
),

EGITIM_KURUM_EGITIM_DATA AS
(SELECT
F_EGITIM_KOD,
F_EGITIM_KURUM_NO,
TEST_YANIT_NO,
SUM(PUAN) AS YANIT_PUAN
FROM
TEST_YANIT_DATA

WHERE
F_EGITIM_KOD IS NOT NULL
AND F_EGITIM_KURUM_NO IS NOT NULL

GROUP BY
F_EGITIM_KOD,
F_EGITIM_KURUM_NO,
TEST_YANIT_NO
),

KURS_DATA AS
(SELECT
F_KURS_NO,
TEST_YANIT_NO,
SUM(PUAN) AS YANIT_PUAN
FROM
TEST_YANIT_DATA
WHERE
F_KURS_NO IS NOT NULL
GROUP BY
F_KURS_NO,
TEST_YANIT_NO
),

KURS_KATILIM_DATA AS
(SELECT
F_KURS_KATILIM_NO,
TEST_YANIT_NO,
SUM(PUAN) AS YANIT_PUAN
FROM
TEST_YANIT_DATA
WHERE
F_KURS_KATILIM_NO IS NOT NULL
GROUP BY
F_KURS_KATILIM_NO,
TEST_YANIT_NO
)

SELECT
F_KURS_NO,
COUNT(TEST_YANIT_NO) AS SAYAC,
SUM(YANIT_PUAN) AS TOPLAM_PUAN,
DOUBLE(SUM(YANIT_PUAN))/COUNT(TEST_YANIT_NO) AS ORTALAMA
FROM
KURS_DATA
GROUP BY
F_KURS_NO
#end
true
?
IK.TEST_YANIT IK.TEST_SORU_YANIT IK.TEST_SORU_SECENEK IK.KURS IK.KURS_KATILIM
?
?