/*****************************************************************************
*
* Filename         - $Workfile:   terminating_counts_v1.sql  $
*
*                     Name              Date      Version     CR Number
*                     Martin Helliwell  20/12/01    1.2        15540
* Author           - See revision history below.
* Last Update      - See revision history below.
*
* Project Name     - TAGTRAK(Oracle Database)
*
* Source Code
* Identifier       - 0/3/300/8010/112
*
* Design Spec
* Section          - 
*
* Contents         - Live Schema View
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 2001
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   terminating_counts_v1.sql  $  $Revision:   1.2  $
*
* Revision History
*
* Note that user tagtrak is many users. For these users the user
* name is entered as the last line in the change description.
*
* $Log:   /pvcsarch/db_ora/db/source/live/views/terminating_counts_v1.svl  $
* 
*    Rev 1.2   20 Dec 2001 13:34:44   tagtrak
* OR:
* CR: 15540
* REV: 1.2
* DESC: Use functions to obtain counts
*
*****************************************************************************/
PROMPT Creating view terminating_counts_v1 

CREATE OR REPLACE FORCE
VIEW terminating_counts_v1 
(flight_id
,flight_no
,flight_dests
,flight_date
,uld_no
,county
,countf
,countc
,counto
,total
) AS
SELECT flight_id
,flight_no
,bag_destination FLIGHT_DESTS
,flight_date
,uld_no
,terminating_count(flight_id,'Y',uld_no, bag_destination) COUNTY
,terminating_count(flight_id,'F',uld_no, bag_destination) COUNTF
,terminating_count(flight_id,'C',uld_no, bag_destination) COUNTC
,terminating_count(flight_id,'O',uld_no, bag_destination) COUNTO
,terminating_count(flight_id,'T',uld_no, bag_destination) TOTAL
FROM bag_v2
WHERE pax_id NOT IN 
(SELECT pax_id FROM onward_flight)
AND delete_marker = 0
AND loaded_status = 'Y'
GROUP BY flight_id
,flight_no
,bag_destination
,flight_date
,uld_no
/
