SELECT
K.MTH AS 'MTH',
SUM(K.DOMESTIC_NO_OF_TICKETS) AS 'DOMESTIC_NO_OF_TICKETS',
SUM(K.DOM_AVERAGE_TICKET_VALUE) AS 'DOM_AVERAGE_TICKET_VALUE',
SUM(K.INTERNATIONAL_NO_OF_TICKETS)
AS
'INTERNATIONAL_NO_OF_TICKETS',
SUM(K.INTL_AVERAGE_TICKET_VALUE) AS 'INTL_AVERAGE_TICKET_VALUE',
SUM(K.TOTAL_TICKETS) AS 'TOTAL_TICKETS',
SUM(K.TOT_AVERAGE_TICKET_VALUE) AS 'TOT_AVERAGE_TICKET_VALUE',
K.SORT AS 'SORT'
FROM
(
(
SELECT
DATE_FORMAT(RAP.DATE_OF_ISSUE,'%M-%Y') AS 'MTH',
IF(RAS.SEGMENT = 0,IF(RAP.DOCTYPE
IN(0,1),1,-1),0) AS 'DOMESTIC_NO_OF_TICKETS',
IF(RAS.SEGMENT = 0,ROUND(SUM(RAS.BASE_FARE
+
RAS.Air_TAX)),0)
AS
'DOM_AVERAGE_TICKET_VALUE',
IF(RAS.SEGMENT = 1,IF(RAP.DOCTYPE
IN(0,1),1,-1),0) AS 'INTERNATIONAL_NO_OF_TICKETS',
IF(RAS.SEGMENT = 1,ROUND(SUM(RAS.BASE_FARE
+
RAS.Air_TAX)),0)
AS
'INTL_AVERAGE_TICKET_VALUE',
"" AS 'TOTAL_TICKETS',
"" AS 'TOT_AVERAGE_TICKET_VALUE',
DATE_FORMAT(RAP.DATE_OF_ISSUE,'%Y%m') AS 'SORT'
FROM
REPT_AIR_PRY_HY1 RAP
INNER JOIN
REPT_AIR_SEC_HY1 RAS
ON(RAP.DOC_SEQ_NO = RAS.DOC_SEQ_NO)
WHERE
RAP.DATE_OF_ISSUE BETWEEN ? AND DATE_ADD(?,INTERVAL
1 DAY)
AND
IF( ? = "" , true , RAP.COMPANY = ? )
AND
IF( ? = "" , true ,
RAP.SERVICE_LOC = ? )
AND
IF( ? = "" , true , RAP.GROUP_CODE
=
?
)
AND
IF( ? = "" , true , RAP.COMP_CODE = ? )
AND
IF( ? = "" , true ,
RAP.SUB_COMP_CODE = ? )
AND
IF(RAS.TICKET_BOOKING_STATUS is null or "" , true ,RAS.TICKET_BOOKING_STATUS
NOT
IN(0,1,2,11,12))
GROUP BY RAP.DOC_ID,RAS.TICKET_NO
)
)AS K
GROUP BY K.MTH
ORDER BY K.SORT
SELECT
K.MTH
AS 'MTH',
SUM(K.DOMESTIC_NO_OF_TICKETS)
AS 'DOMESTIC_NO_OF_TICKETS',
SUM(K.DOM_AVERAGE_TICKET_VALUE)
AS 'DOM_AVERAGE_TICKET_VALUE',
SUM(K.INTERNATIONAL_NO_OF_TICKETS)
AS 'INTERNATIONAL_NO_OF_TICKETS',
SUM(K.INTL_AVERAGE_TICKET_VALUE)
AS 'INTL_AVERAGE_TICKET_VALUE',
SUM(convert(int ,K.TOTAL_TICKETS)) AS 'TOTAL_TICKETS',
SUM(convert(int ,K.TOT_AVERAGE_TICKET_VALUE))
AS 'TOT_AVERAGE_TICKET_VALUE',
K.SORT
AS 'SORT'
FROM
((
SELECT
datename(month,RAP.DATE_OF_ISSUE) +'-'+convert(varchar,datepart(year,RAP.DATE_OF_ISSUE)) AS 'MTH',
(case when ras.segment=0 then (case when rap.doctype in(0,1) then 1 else -1 end) else 0 end) as 'DOMESTIC_NO_OF_TICKETS',
--
IF(RAS.SEGMENT = 0,IF(RAP.DOCTYPE IN(0,1),1,-1),0) AS 'DOMESTIC_NO_OF_TICKETS',
case when RAS.SEGMENT = 0 then ROUND(SUM(RAS.BASE_FARE + RAS.Air_TAX),0) else 0 end as 'DOM_AVERAGE_TICKET_VALUE',
--IF(RAS.SEGMENT
= 0,ROUND(SUM(RAS.BASE_FARE + RAS.Air_TAX)),0) AS 'DOM_AVERAGE_TICKET_VALUE',
case when RAS.SEGMENT = 1 then (case when rap.doctype in(0,1) then 1 else -1 end) else 0 end as 'INTERNATIONAL_NO_OF_TICKETS',
--IF(RAS.SEGMENT
= 1,IF(RAP.DOCTYPE IN(0,1),1,-1),0) AS 'INTERNATIONAL_NO_OF_TICKETS',
case when RAS.SEGMENT = 1 then ROUND(SUM(RAS.BASE_FARE + RAS.Air_TAX),0) else 0 end as 'INTL_AVERAGE_TICKET_VALUE',
--IF(RAS.SEGMENT
= 1,ROUND(SUM(RAS.BASE_FARE + RAS.Air_TAX)),0) AS 'INTL_AVERAGE_TICKET_VALUE',
' ' AS
'TOTAL_TICKETS',
' ' AS
'TOT_AVERAGE_TICKET_VALUE',
convert(varchar,datepart(year,RAP.DATE_OF_ISSUE))+''+datename(month,RAP.DATE_OF_ISSUE) AS 'SORT'
FROM
REPT_AIR_PRY_HY1 RAP
INNER JOIN
REPT_AIR_SEC_HY1 RAS
ON(RAP.DOC_SEQ_NO = RAS.DOC_SEQ_NO)
where RAP.DATE_OF_ISSUE BETWEEN
'2012-02-01' AND
DATEADD(DD, 1, '2012-04-01')
--AND
RAS.TICKET_BOOKING_STATUS NOT IN(0,1,2,11,12)
--AND CASE WHEN
RAS.TICKET_BOOKING_STATUS IS NULL OR '' THEN RAS.TICKET_BOOKING_STATUS =(SELECT
DISTINCT(RAS.TICKET_BOOKING
--AND
IF(RAS.TICKET_BOOKING_STATUS is null or "" , true
,RAS.TICKET_BOOKING_STATUS NOT IN(0,1,2,11,12))
GROUP BY RAP.DOC_ID,RAS.TICKET_NO,RAP.DATE_OF_ISSUE,RAS.SEGMENT,rap.doctype))
as K
group by K.MTH,K.SORT
ORDER BY K.SORT
No comments:
Post a Comment