Average time between diferrent dates in the same table

I am having a big problem trying to get this sentence for my report the thing is that I have a table name ca_parking
ca_parking (
id_parking number,
date_in date,
date_out date,
id_truck number,
id_user_rec number,
date_rec date);
where date_in and date_out are the day and time where truck get in and out of the building, id_parking is the pk of the table, id_truck is the fk from table ca_truck, id_user_rec is the user who enters the data on the system, anda date_rec is the date when the record is inserted.The company asked for an average of time spent by the trucks inside the parking lots so i need to use the date_in from one record less the date out from the next record of the same truck
id_parking date_in date_out id_truck id_user_rec date_rec
451794     03/07/2012 8:50:00     02/07/2012 20:00:00     36937     MFUERTE     02/07/2012 20:08:16
452580     05/07/2012 7:00:00     04/07/2012 20:15:00     36937     VCONTRERAS 04/07/2012 13:56:33
451591     02/07/2012 18:00:00     02/07/2012 13:00:00     47393     OVILLACIS     02/07/2012 13:39:40
451824     03/07/2012 17:00:00     03/07/2012 7:00:00     47393     OVILLACIS     03/07/2012 7:06:37
453160     05/07/2012 17:00:00     05/07/2012 14:50:00     47393     WALEMA     05/07/2012 14:57:51
So i need to do something like this
select avg(ca_parking.date_in - ca_parking.date_out), ca_trucks.trcuk_alias from ca_parking, ca_trucks where ca_parking.id_truck = ca_trucks.id_truck
group by ca_trucks.trcuk_alias
but i get only trash
I need it to do this for truck 36937 { (04/07/2012 20:15:00 - 03/07/2012 8:50:00) + (sysdate-05/07/2012 7:00:00)}/2 = 4.37
and fro truck 47393 { (03/07/2012 7:00:00 -  02/07/2012 18:00:00) + (05/07/2012 14:50:00 - 03/07/2012 17:00:00) + (sysdate - 05/07/2012 17:00:00)}/2 = 4.65
how can i get the following date_out less the previews date_in

I am having a big problem trying to get this sentence for my report the thing is that I have a table name ca_parking
ca_parking (
id_parking number,
date_in date,
date_out date,
id_truck number,
id_user_rec number,
date_rec date);
where date_in and date_out are the day and time where truck get in and out of the building, id_parking is the pk of the table, id_truck is the fk from table ca_truck, id_user_rec is the user who enters the data on the system, anda date_rec is the date when the record is inserted.The company asked for an average of time spent by the trucks inside the parking lots so i need to use the date_in from one record less the date out from the next record of the same truck
id_parking date_in date_out id_truck id_user_rec date_rec
451794     03/07/2012 8:50:00     02/07/2012 20:00:00     36937     MFUERTE     02/07/2012 20:08:16
452580     05/07/2012 7:00:00     04/07/2012 20:15:00     36937     VCONTRERAS 04/07/2012 13:56:33
451591     02/07/2012 18:00:00     02/07/2012 13:00:00     47393     OVILLACIS     02/07/2012 13:39:40
451824     03/07/2012 17:00:00     03/07/2012 7:00:00     47393     OVILLACIS     03/07/2012 7:06:37
453160     05/07/2012 17:00:00     05/07/2012 14:50:00     47393     WALEMA     05/07/2012 14:57:51
So i need to do something like this
select avg(ca_parking.date_in - ca_parking.date_out), ca_trucks.trcuk_alias from ca_parking, ca_trucks where ca_parking.id_truck = ca_trucks.id_truck
group by ca_trucks.trcuk_alias
but i get only trash
I need it to do this for truck 36937 { (04/07/2012 20:15:00 - 03/07/2012 8:50:00) + (sysdate-05/07/2012 7:00:00)}/2 = 4.37
and fro truck 47393 { (03/07/2012 7:00:00 -  02/07/2012 18:00:00) + (05/07/2012 14:50:00 - 03/07/2012 17:00:00) + (sysdate - 05/07/2012 17:00:00)}/2 = 4.65
how can i get the following date_out less the previews date_in

Similar Messages

  • Calculating average time from two records from the same table.

    Hi all
    I need to calculate the average time between two events that are recorded in the same table.
    The table is TMS_MESSAGE_AUDIT_LOG
    MESSAGE_ID VARCHAR2(16 BYTE) NOT NULL,
    MESSAGE_VERSION NUMBER(2) NOT NULL,
    CREATE_TM VARCHAR2(18 BYTE) NOT NULL,
    MESSAGE_STATUS VARCHAR2(30 BYTE),
    TRANSACTION_TYPE_NM VARCHAR2(30 BYTE),
    MESSAGE_TP VARCHAR2(3 BYTE),
    WORKFLOW_OBJECT VARCHAR2(30 BYTE) NOT NULL,
    WORKFLOW_REQUEST VARCHAR2(30 BYTE) NOT NULL,
    WORKFLOW_RETURN_CD VARCHAR2(30 BYTE) NOT NULL,
    AUDIT_ACTION VARCHAR2(255 BYTE),
    LAST_UPDATE_USER_LOGON_ID VARCHAR2(12 BYTE),
    LOCAL_TM VARCHAR2(18 BYTE) NOT NULL,
    LOCAL_TIME_ZN_NM VARCHAR2(70 BYTE) NOT NULL,
    LOCAL_DAYLIGHT_IN CHAR(1 BYTE) NOT NULL,
    FPRINT VARCHAR2(30 BYTE)
    What i now need is
    When the MESSAGE_ID is the same i need have the average time between when the MESSAGE_STATUS is AA and BB ( I need the time out of the CREATE_TM field )
    And this for every 15 minutes interval.
    Because this table will become BIG millions and millions of records it needs to be fast.
    Can anybody help me.
    Marcel

    Something like this?
    CREATE TABLE wr_test
    ( message_id                 VARCHAR2(16 BYTE) NOT NULL
    , message_version            NUMBER(2) NOT NULL  -- Assumption: Acknowledged ver > Received ver
    , create_tm                  VARCHAR2(18 BYTE) NOT NULL
    , message_status             VARCHAR2(30 BYTE)
    , transaction_type_nm        VARCHAR2(30 BYTE)
    , workflow_object            VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
    , workflow_request           VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
    , workflow_return_cd         VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
    , audit_action               VARCHAR2(255 BYTE)
    , last_update_user_logon_id  VARCHAR2(12 BYTE)
    , local_tm                   VARCHAR2(18 BYTE) NOT NULL
    , local_time_zn_nm           VARCHAR2(70 BYTE) DEFAULT 'GMT' NOT NULL
    , local_daylight_in          CHAR(1 BYTE) DEFAULT 'x' NOT NULL );
    INSERT ALL
    INTO   wr_test
           ( message_id
           , message_version
           , create_tm
           , message_status
           , local_tm )
    VALUES ( message_id
           , 1
           , create_tm
           , '(Receive)'
           , TO_CHAR(local_tm,'YYYYMMDD HH24:MI:SS') )
    INTO   wr_test
           ( message_id
           , message_version
           , create_tm
           , message_status
           , local_tm )
    VALUES ( message_id
           , 2
           , create_tm
           , 'Wait CLSB Ack'
         , TO_CHAR
           ( local_tm + NUMTODSINTERVAL(DBMS_RANDOM.VALUE(0,2e5),'SECOND')
           , 'YYYYMMDD HH24:MI:SS' ) )
    SELECT ROWNUM AS message_id
         , TO_CHAR(SYSDATE,'YYYYMMDD HH24:MI:SS') AS create_tm
         , DATE '2000-01-01' + DBMS_RANDOM.VALUE(0,3) AS local_tm
    FROM dual CONNECT BY ROWNUM < 100000;
    WITH src AS
         ( SELECT message_id
                , message_status
                , message_version
                , TO_DATE(SUBSTR(local_tm,1,17),'YYYYMMDD HH24:MI:SS') AS dt
                , TO_DATE(SUBSTR(local_tm,1,8),'YYYYMMDD') AS dt_day
                , TO_CHAR(TO_DATE(SUBSTR(local_tm,10,8),'HH24:MI:SS'),'SSSSS') AS dt_sec
           FROM   wr_test
           WHERE  message_status IN ('(Receive)','Wait CLSB Ack') )
    SELECT dt_day + NUMTODSINTERVAL(period,'SECOND') AS dt
         , NUMTODSINTERVAL(AVG(elapsed),'DAY') AS avg_elapsed
         , NUMTODSINTERVAL(MIN(elapsed),'DAY') AS min_elapsed
         , NUMTODSINTERVAL(MAX(elapsed),'DAY') AS max_elapsed
         , COUNT(*)
    FROM   ( SELECT message_id
                  , message_status
                  , dt_day
                  , TRUNC(dt_sec/300)*300 AS period
                  , LEAD(dt) OVER (PARTITION BY message_id ORDER BY message_version) AS ack_dt
                  , LEAD(dt) OVER (PARTITION BY message_id ORDER BY message_version) - dt AS elapsed
             FROM   src ) cal
    WHERE  cal.message_status = '(Receive)'
    GROUP BY dt_day, period
    ORDER BY 1;Replace "wr_test" with "tms_message_audit_log" in the WITH subquery to test on your data.

  • How to populate data in the same table based on different links/buttons

    Hi
    I'm using jdeveloper 11.1.4. I have a use case in which i need to populate data in the same table based on click of different links.
    Can anyone please suggest how can this be achieved.
    Thanks

    I have a use case in which i need to populate data in the same table based on click of different linksDo you mean that you need to edit existing rows ?
    What format do you have the date in - table / form ?

  • How to update a table (CUSTOMER) on a Report Server with the data from the same table (CUSTOMER) from another server Transaction server?

    I had an interview question that is:
    How to update a table (Customer) on a server ex: Report Server with the data from the same table (Customer) From another server ex: Transaction server?
    Set up steps so inset, update or delete operation takes place across the servers.
    It would be great if someone please enlighten me in details about this process in MS SQL Server 2008 R2.
    Also please describe would it be different for SQL Server 2012?
    If so, then what are the steps?

    I had an interview question that is:
    How to update a table (Customer) on a server ex: Report Server with the data from the same table (Customer) from another server ex: Transaction server?
    Set up steps so that inset, update or delete operation gets done correctly across servers.
    I was not sure about the answer, it would be great if someone please put some light on this and explain in details about this process in MS SQL Server 2008 R2.
    Also it would be very helpful if you please describe would it be different for SQL Server 2012? If so, then what are the steps?

  • Historical and transaction data in the same tables creates perf problems

    Our Oracle based application is slow partly due to the fact that historical data are kept in the same table as transactional data. For example records about deceased patients, patients treated 5 years ago...etc, are kept in the one and only one patient table, which is needed to run the daily process of the hospital. So gradually all our major tables PATIENTS, CHARTS, NAMES, APPOINTMENTS have grown very large and since most of our SQL join all these tables at the same time, then all screens and reports run very slowly. I have introduced the idea that we should split all these tables in two: historical PATIENTS data, and CURRENT PATIENTS data...the same with all the others. A nice system would first search in the smaller transactional tables, which would run faster being smaller, and if no data found, then fallback to the historical tables. But this would require programming. From what I have read mateialized view could solve part of our problem. We could have views containing for example only one year worth of the data, and I guess any changes could be later replicated in the base table. What I dont know is what to do if we cannot find the patient in the matealized views ? Do I need to fallback to another SQL which will search in the initial base tables ? Anyway we can implement this without programming ? Tx.

    Appointment table: 207,470
    Visit table: 5,890,920
    Patient table: 2,993,129
    Chart table: 2,864,069
    Patient names table: 3,938,118
    SELECT
        APPOI_OR_VISIT,
        VISIT_SEQ,
        PAT_SEQ,
        INST_CODE,
        INST_CODE_DISPL,
        INST_DESC,
        CLINIC_CODE,
        CLINIC_CODE_DISPL,
        CLINIC_DESC,
        SPEC_CODE,
        SPEC_CODE_DISPL,
        SPEC_DESC,
        VISIT_DATE,
        VISIT_TIME,
        VISIT_TIME_ARRIVAL,
        APPTYPE_CODE,
        SESSION_DOM_MODE,
        PRESTYPE_CODE,
        PRESTYPE_DOM_TYPE,
        DIA_CODE,
        VISIT_TIME_START_RESP,
        VISIT_TIME_DISCHARGE,
        APPOI_NB_DURATION,
        VISIT_TX_REASON,
        VISIT_TX_COMMENT,
        EXTDOC_CODE,
        VISIT_PN_REFPHYS_NAME,
        PATYPE_CODE,
        PAYRESP_CODE,
        VISIT_IND_GROUP,
        VISIT_PCODE,
        VISIT_IND_COMPLETE,
        VISIT_IND_ADMISSION,
        VISIT_IND_CONFIDENTIALITY,
        VISIT_DATE_ACCIDENT,
        APPOI_SEQ,
        BILLING_CODE,
        VISIT_TX_DIAGNOSIS,
        CST_CODE_1,
        CST_CODE_2,
        CST_CODE_3,
        APPOI_DH_CRE,
        APPOI_CODE_CRE_USER,
        APPOI_DH_MOD,
        APPOI_CODE_MOD_USER,
        VISIT_CODE_CRE_USER,
        VISIT_DH_CRE,
        VISIT_UPDATED_COUNT,
        VISIT_CODE_MOD_USER,
        VISIT_DH_MOD,
        APPOI_PAYRESP_CODE,
        APPOI_DT_ACCIDENT,
        PATIENT_LAST_NAME,
        PATIENT_FIRST_NAME,
        PATIENT_CONFIDENTIALITY,
        PATIENT_CHART_EXT,
        TO_NUMBER(SUBSTR(PATIENT_CHART_EXT, 1, INSTR(PATIENT_CHART_EXT, '|')-1)) AS PATIENT_CHART_NO,
        PAT_IND_SPECIAL_RISK
    FROM
        SELECT
            'VISIT'              AS APPOI_OR_VISIT,
            VISIT.VISIT_SEQ,
            VISIT.PAT_SEQ,
            INSTITUTION.INST_CODE,
            INSTITUTION.INST_CODE_DISPL,
            INSTITUTION.INST_DESC,
            CLINIC.CLINIC_CODE,
            CLINIC.CLINIC_CODE_DISPL,
            CLINIC.CLINIC_DESC,
            SPECIALTY.SPEC_CODE,
            SPECIALTY.SPEC_CODE_DISPL,
            SPECIALTY.SPEC_DESC,
            VISIT.VISIT_DATE,
            VISIT.VISIT_TIME,
            VISIT.VISIT_TIME_ARRIVAL,
            VISIT.APPTYPE_CODE,
            VISIT.SESSION_DOM_MODE,
            VISIT.PRESTYPE_CODE,
            VISIT.PRESTYPE_DOM_TYPE,
            VISIT.DIA_CODE,
            VISIT.VISIT_TIME_START_RESP,
            VISIT.VISIT_TIME_DISCHARGE,
            VISIT.APPOI_NB_DURATION,
            VISIT.VISIT_TX_REASON,
            VISIT.VISIT_TX_COMMENT,
            VISIT.EXTDOC_CODE,
            VISIT.VISIT_PN_REFPHYS_NAME,
            VISIT.PATYPE_CODE,
            VISIT.PAYRESP_CODE,
            VISIT.VISIT_IND_GROUP,
            VISIT.VISIT_PCODE,
            VISIT.VISIT_IND_COMPLETE,
            VISIT.VISIT_IND_ADMISSION,
            VISIT.VISIT_IND_CONFIDENTIALITY,
            VISIT.VISIT_DATE_ACCIDENT,
            VISIT.APPOI_SEQ,
            VISIT.BILLING_CODE,
            VISIT.VISIT_TX_DIAGNOSIS,
            VISIT.CST_CODE_1,
            VISIT.CST_CODE_2,
            VISIT.CST_CODE_3,
            VISIT.APPOI_DH_CRE,
            VISIT.APPOI_CODE_CRE_USER,
            VISIT.APPOI_DH_MOD,
            VISIT.APPOI_CODE_MOD_USER,
            VISIT.VISIT_CODE_CRE_USER,
            VISIT.VISIT_DH_CRE,
            VISIT.VISIT_UPDATED_COUNT,
            VISIT.VISIT_CODE_MOD_USER,
            VISIT.VISIT_DH_MOD,
            NULL AS APPOI_PAYRESP_CODE,
            TO_DATE(NULL) AS APPOI_DT_ACCIDENT,
            NAME.NAM_PN_NAM AS PATIENT_LAST_NAME,
            NAME.NAM_PN_FNAM AS PATIENT_FIRST_NAME,
            CONFIDENTIALITY.CONF_DESC AS PATIENT_CONFIDENTIALITY,
            PI_SECURITY.F_GET_CHART_NUMBER_SCAN_CODE(VISIT.PAT_SEQ, 103 /*:pChartInstitutionID*/, 0) AS PATIENT_CHART_EXT,
            PATIENT.PAT_IND_SPECIAL_RISK
        FROM
                   AS_T_VISITS        VISIT,
                   CT_R_INSTITUTIONS  INSTITUTION,
                   AS_T_CLINICS       CLINIC,
                   CT_R_SPECIALITIES  SPECIALTY,
                   PI_T_NAMES         NAME,
                   PI_T_PATIENTS      PATIENT,
                   PI_R_CONF_LEVELS   CONFIDENTIALITY
        WHERE
            VISIT_DATE >= TO_DATE('2004-04-01', 'YYYY-MM-DD') /*:P_VISIT_DATE_FROM*/ AND
            VISIT_DATE <= TO_DATE('2004-04-02', 'YYYY-MM-DD') /*::P_VISIT_DATE_TO*/ AND
            CLINIC.CLINIC_CODE = VISIT.CLINIC_CODE AND
            SPECIALTY.SPEC_CODE = CLINIC.SPEC_CODE AND
            INSTITUTION.INST_CODE(+) = VISIT.INST_CODE AND
            NAME.PAT_SEQ = VISIT.PAT_SEQ AND
            NAME.NAMTYP_CODE = 1 AND
            PATIENT.PAT_SEQ = VISIT.PAT_SEQ AND
            CONFIDENTIALITY.CONF_CODE (+) = PATIENT.CONF_CODE
        UNION
        SELECT
            'APPOI'                                                                                                                                                                                                        AS APPOI_OR_VISIT,
            0                                                                                                                                                                                                                            AS VISIT_SEQ,
            NVL(APPOINTMENT_GROUP.PAT_SEQ, APPOINTMENT.PAT_SEQ) AS PAT_SEQ,
            INSTITUTION.INST_CODE,
            INSTITUTION.INST_CODE_DISPL,
            INSTITUTION.INST_DESC,
            CLINIC.CLINIC_CODE,
            CLINIC.CLINIC_CODE_DISPL,
            CLINIC.CLINIC_DESC,
            SPECIALTY.SPEC_CODE,
            SPECIALTY.SPEC_CODE_DISPL,
            SPECIALTY.SPEC_DESC,
            APPOINTMENT.SESSION_DATE                                                                                                                                                                AS VISIT_DATE,
            APPOINTMENT.APPOI_TIME                                                                                                                                                                     AS VISIT_TIME,
            ''                                                                                                                                                                                                                  AS VISIT_TIME_ARRIVAL,
            APPOINTMENT.APPTYPE_CODE,
            APPOINTMENT.SESSION_DOM_MODE,
            0                                                                                                                                                                                                                            AS PRESTYPE_CODE,
            ''                                                                                                                                                                                                                  AS PRESTYPE_DOM_TYPE,
            0                                                                                                                                                                                                                            AS DIA_CODE,
            ''                                                                                                                                                                                                                  AS VISIT_TIME_START_RESP,
            ''                                                                                                                                                                                                                  AS VISIT_TIME_DISCHARGE,
            APPOINTMENT.APPOI_NB_DURATION,
            APPOINTMENT.APPOI_TX_REASON                                                                                                                                                           AS VISIT_TX_REASON,
            APPOINTMENT.APPOI_TX_COMMENT                                                                                                                                                      AS VISIT_TX_COMMENT,
            APPOINTMENT.EXTDOC_CODE,
            APPOINTMENT.APPOI_PN_REFPHYS_NAME                                                                                                                                            AS VISIT_PN_REFPHYS_NAME,
            APPOINTMENT_TYPE.PATYPE_CODE  AS PATYPE_CODE,
            0                                                                                                                                                                                                                            AS PAYRESP_CODE,
            DECODE(APPOINTMENT_GROUP.PAT_SEQ,NULL,0,1)                                                                                                                   AS VISIT_IND_GROUP,
            ''                                                                                                                                                                                                                  AS VISIT_PCODE,
            0                                                                                                                                                                                                                            AS VISIT_IND_COMPLETE,
            0                                                                                                                                                                                                                            AS VISIT_IND_ADMISSION,
            APPOINTMENT.APPOI_IND_CONFIDENTIALITY                                                                                                                                  AS VISIT_IND_CONFIDENTIALITY,
            TO_DATE(NULL)                                                                                                                                                                                          AS VISIT_DATE_ACCIDENT,
            APPOINTMENT.APPOI_SEQ,
            0                                                                                                                                                                                                                            AS BILLING_CODE,
            ''                                                                                                                                                                                                                  AS VISIT_TX_DIAGNOSIS,
            0                                                                                                                                                                                                                            AS CST_CODE_1,
            0                                                                                                                                                                                                                            AS CST_CODE_2,
            0                                                                                                                                                                                                                            AS CST_CODE_3,
            APPOINTMENT.APPOI_DH_CRE                                                                                                                                                                AS APPOI_DH_CRE,
            APPOINTMENT.APPOI_CODE_CRE_USER                                                                                                                                                 AS APPOI_CODE_CRE_USER,
            APPOINTMENT.APPOI_DH_MOD                                                                                                                                                                AS APPOI_DH_MOD,
            APPOINTMENT.APPOI_CODE_MOD_USER                                                                                                                                                 AS APPOI_CODE_MOD_USER,
            ''                                                                                                                                                                                                                  AS VISIT_CODE_CRE_USER,
            SYSDATE                                                                                                                                                                                                             AS VISIT_DH_CRE,
            0                                                                                                                                                                                                                            AS VISIT_UPDATED_COUNT,
            ''                                                                                                                                                                                                                  AS VISIT_CODE_MOD_USER,
            SYSDATE                                                                                                                                                                                                             AS VISIT_DH_MOD,
            PAYRESP_CODE                                                                             AS APPOI_PAYRESP_CODE,
            APPOI_DT_ACCIDENT,
            NAME.NAM_PN_NAM AS PATIENT_LAST_NAME,
            NAME.NAM_PN_FNAM AS PATIENT_FIRST_NAME,
            CONFIDENTIALITY.CONF_DESC AS PATIENT_CONFIDENTIALITY,
                                        PI_SECURITY.F_GET_CHART_NUMBER_SCAN_CODE(APPOINTMENT.PAT_SEQ, 103 /*:pChartInstitutionID*/, 0) AS PATIENT_CHART_EXT,
            PATIENT.PAT_IND_SPECIAL_RISK
        FROM
                   AS_T_APPOINTMENTS       APPOINTMENT,
                   AS_R_APPOINTMENT_TYPES  APPOINTMENT_TYPE,
                   AS_T_CLINICS            CLINIC,
                   CT_R_SPECIALITIES       SPECIALTY,
                   CT_R_INSTITUTIONS       INSTITUTION,
                   AS_T_APPOINTMENT_GROUPS APPOINTMENT_GROUP,
                   PI_T_PATIENTS           PATIENT,
                   PI_R_CONF_LEVELS        CONFIDENTIALITY,
                   PI_T_NAMES              NAME,
                   AS_T_APPOINTMENT_SEQ_MAPPING  SEQMAP
        WHERE
            SESSION_DATE >= TO_DATE('2004-04-01', 'YYYY-MM-DD') /*:P_VISIT_DATE_FROM*/ AND
            SESSION_DATE <= TO_DATE('2004-04-02', 'YYYY-MM-DD') /*::P_VISIT_DATE_TO*/ AND
            APPOINTMENT.APPOI_DOM_TYPE IN('A','AR') AND
            CLINIC.CLINIC_CODE = APPOINTMENT.CLINIC_CODE AND
            SPECIALTY.SPEC_CODE = CLINIC.SPEC_CODE AND
            INSTITUTION.INST_CODE(+) = APPOINTMENT.INST_CODE AND
            APPOINTMENT_GROUP.APPOI_SEQ (+) = APPOINTMENT.APPOI_SEQ AND
            APPOINTMENT_TYPE.APPTYPE_CODE (+) = APPOINTMENT.APPTYPE_CODE AND
            NAME.PAT_SEQ = NVL(APPOINTMENT.PAT_SEQ, APPOINTMENT_GROUP.PAT_SEQ) AND
            NAME.NAMTYP_CODE = 1 AND
            PATIENT.PAT_SEQ = NVL(APPOINTMENT.PAT_SEQ, APPOINTMENT_GROUP.PAT_SEQ) AND
            CONFIDENTIALITY.CONF_CODE (+) = PATIENT.CONF_CODE AND
            SEQMAP.APPOI_SEQ (+) = APPOINTMENT.APPOI_SEQ AND
            SEQMAP.APPOI_SEQ IS NULL
    ORDER BY
         VISIT_DATE, VISIT_TIME, PATIENT_CHART_NO

  • Retrieve data from the same table

    i have a table with following fields
    emp_no,name,salary,department,dept_prev,prev_emp_no.
    now i want retrieve emp_no,name,salary,department, from the data base for a perticular employeee number along with dept_prev
    but dept_prev is the prev_emp_no dept_prev
    now iam doing two query like this
    first query to retreive name,salary,department
    select name,salary,department from employee where emp_no = 10
    second to retrieve the dept_prev from the same table but this
    dept_prev must be based on prev_emp_no
    select dept_prev from employee where emp_no in(select prev_emp_no from employee where emp_no =10)
    can any one suggest to combine these two queries in a single sql statements, because all the fieldds are from the same table.
    Thanks

    Would this one solve it?
    SELECT emp.NAME, emp.salary, emp.department,
           prev_emp.dept_prev
      FROM employee emp,
           employee prev_emp
    WHERE emp.emp_no      = 10
       AND prev_emp.emp_no = emp.prev_emp_no;
    not tested
    C.

  • How to read the hierarchy data from the same table using loop in AMDP method

    Hi All,
    We have a requirement to get the top partner from BUT050 table.
    Here the Top parent is nothing but the top most in the hierarchy of the partners from BUT050.
    Example:
    For partner 1234 (BUT050-PARTNER1) there is partner 3523(BUT050-PARTNER2) one level above
    For partner 3523(BUT050-PARTNER1)  there is partner 4544 (BUT050-PARTNER2) last level .
    so in this case for the partner 1234 the Top parent is 4544 .
    I have created AMDP Procedure method to get the top-parnet and below given is the logic implemented in AMDP method.
    Here i have implemented a recursive logic with the WHILE loop to get the top most hierarchy partner from the same table BUT050
    IV_Parent is the input partner and ev_top_parent is the output value.
    AMDP Procedure Method:
        DECLARE lv_date VARCHAR(8) := TO_VARCHAR (current_date, 'YYYYMMDD');
        DECLARE found INT := 1;
              iv_partner1 =  SELECT partner1 FROM but050
                              WHERE partner2 = iv_partner
                              AND reltyp = :iv_hierarchy
                              AND date_to >=  :lv_date
                              AND date_from <= :lv_date;
         WHILE found <> 0  do
           select partner1 into ev_top_parent from :iv_partner1;
                           iv_partner1 =  SELECT partner1 FROM but050
                           WHERE partner2 in ( select partner1 from :iv_partner1 where partner1 is not null)
                           AND reltyp = 'ZBP004'
                           AND date_to >= :lv_date
                           AND date_from <= :lv_date;
           select COUNT ( partner1 ) INTO found FROM :IV_PARTNER1;
        END WHILE;
    This method is working fine, but here it is only taking one single partner and getting the top parent as output.
    Now i would like to convert this mehtod so as to accept n number of partners (not one single partner) as input and should process each partner to get the top parent.
    Could anyone guide me how can i handle the given AMDP method further so as to work some how it is within another loop from other AMDP method.
    Thanks.
    Regards,
    Laxman.P

    Hi
    Go to SE11 and enter the hierarchy table name.
    /BIC/H....(infoobject name)...and execute the table and select table entry and delete all....
    Thanks
    TG

  • Want to select individual data as well as aggregate data from the same table

    want to select a, b  from tab1  also need to find in the same table  tab1 need to do sum(b) group by a

    SELECT a,b,0 AS Ord
    FROM tab1
    UNION ALL
    SELECT a,SUM(b),1
    FROM tab1
    GROUP BY a
    ORDER BY a,Ord
    assuming SQL Compact
    If its SQL Server then we have much simpler methods
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Query - Get data from the same table and field two times on a single line

    I have prepared a query showing the bill of material. At each line each component will be a new line and I want to have the description of the material at the top (the master material composed of the component ones) and also the description of the component materials on the same line. This means that I should be able to use MAKT table 2 times on a single line of the query. I have used the query tool with SQ01 and SQ02 tcodes. How can I get the the description of the material at the top and also the description of the component material on a single line?
    Thanks in advance for the answers.

    Yasar,
    Any time you wish to use a table twice in an SQ01 query, you have to create an alias.
    SQ02 > select the infoset, 'change' > go to Join definitions.
    Select 'Alias' button.  Create. Select your table name (such as MAKT) and define an alias, such as 'COMP_MAKT' for component descriptions.
    Now you can insert the Alias table into your infoset just like it was a regular table, and use standard join method to join COMP_MAKT to your component material number.
    Best regards,
    DB49

  • Multiple language data in the same table and indexes

    We have 8.1.5 database with
    NLS_LANGUAGE=ENGLISH and NLS_TERRITORY=UNITED KINGDOM set at the database level. We also set the NLS_LANG appropriately when we index the data. We also use the preference setting BASE_LETTER=YES when indexing.
    Our tables contain book titles which is what we index using interMedia. Being an online book store, this table may contain titles in English (most of the titles are in English being UK) and some titles in French. Please note the French language has accents and diacritics. Normally in a French database with NLS parameters set correctly and BASE_LETTER=YES, if we search for a title with accent / diacritic it will return the record correctly and match the rows with or without the accents (e.g. searching for video will return both vidio (not the accent on e) and video). However, with the UK settings the accents are not ignored during indexing and it only returns the records that exactly match the search word (e.g. searching for video returns only video and searching for vidio returns only vidio (note the accents on e in the last two videos)).
    Question: Is there any way to appropriately index multiple language specific titles in the same database? If yes, how? Is it possible at all? Suggestions, ideas are welcome.
    null

    Similar request; if there are several different languages used in a database, but a search word can be typed in by anyone and not necessarily in the default language, I still want to be able to pick up all the records (including text in blobs) in any language where my search word = the equivelant word in the other languages; eg. searching on "tree", the search would bring back a document that contained "l'arbre". I then want to set the default language, and allow the user to select a "search in these languages" option to expand the search from the default "tree" to all languages in the database.
    I know about the multi_Lexer but does it extend functionality to this level?

  • Comparing SQL data in the same table for two different dates

    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
    Hello,
    We have a batch scheduling tool that automatically runs Oracle jobs and when it runs the jobs it stores a record from the instance in a table. I am trying to write a query that pulls up all of the jobs that ran today and compares them with what ran on the same day last week to find out what jobs didnt run today. So far I have the below but I can't get it to return anything. I am using Toad for this
    select *
    from xxcar_abat_instances
    where trunc(to_date(start_datetime)) = trunc(sysdate-7)
      and completion_status = 'Success'
    AND NOT EXISTS
      (select script_name
        from xxcar_abat_instances
       where trunc(to_date(start_datetime)) = trunc(sysdate)
         and completion_status = 'Success')Thank you

    Hi,
    964188 wrote:
    It is a date
    Such as
    10/31/2012 11:55:03 PMThen, as Hoek says, you don't want TO_DATE. For example:
    WHERE   TRUNC (start_datetime) = TRUNC (SYSDATE - 7) or the more efficient
    WHERE   start_datetime >= TRUNC (SYSDATE - 7)
    AND     start_datetime <  TRUNC (SYSDATE - 6)Also, it doesn't look like the EXISTS sub-query is corelated to the main query. That's almost certainly a mistake.
    If you're still having trouble, post your revised query, a little sample data (CREATE TABLE and INSERT statements). Point out where that query is givimg the wrong results, and explain how to get te right results.
    See the forum FAQ {message:id=9360002}

  • Is it possible to view/compare two Time Machine desktop dates at the same time?

    I accidentally lost a file on my desktop, inadvertently dragging it onto my browser. I don't know what file I lost, and would like to retrieve it through my Time Machine.  I don't want to replace all of the files on my desktop, but I would like to compare the files from two different dates (current date and last time saved) to discover the file I lost. If there's an easier way to make this discovery, I'm open for suggestions. Otherwise, I wonder if there's a way to see or compare my current   files on desktop vs. my last save to Time Machine (without printing out a list).
    Thanks in advance for your help!

    Hey apple_peeler,
    Thanks for using Apple Support Communities.
    It sounds like you want to find out what is now missing by comparing it with other backups. The Restoring data from Time Machine backups section explains how you can do that.
    Mac Basics: Time Machine backs up your Mac
    http://support.apple.com/kb/HT1427
    You can use the timeline on the right side of the window to reach a certain point back in time. The timeline shows the times of all backups on your backup drive. If you don’t know exactly when you deleted or changed a file, you can use the back arrow to let Time Machine automatically travel through time to show you when that folder last changed.
    Have a nice day,
    Mario

  • How to show grouped data in the same table?

    Hi,
    I am using JDev 11.1.1.2.0 with ADF 11g.
    I have a below requirement
    I have a tbl as below
    Columns -==> RC TL Code
    Data ==> 0 0 Prof
    0 1 Prin
    0 2 Tech
    1 0 Prin
    1 2 Prof
    I prepared a query with a grouping on TL so that I can show my data as below
    TL - 0
    RC Code
    0 Prof
    1 Prin
    TL - 1
    RC Code
    1 Prin
    TL - 2
    RC Code
    0 Tech
    2 Prof
    Really confused on to what type of component should I use and how can the component be repeated once dragged and dropped onto the canvas. Is this possible using ADF? If not what is the alternative?
    Thanks in advance.

    Hi Bharat,
      Unload the Repository and Delete the Table and fields in Hierarchy table and Recreate and reload the data.OIther wise you have to lot of manual work.
    Thanks
    Ganesh Kotti

  • Update multiple rows with datas from the same table

    i have a table like
    name version value1 value2
    2 A 4,31 3,5
    3 A 3,45 10
    2 B 6,97 12
    4 B 12 16
    so name + version is unique
    i have to update the datas value1 and value2 ( version A) with the datas from version B where the name ( VersionA) = name version B
    i.e the result should be
    name version value1 value2
    2 A 6,97 12
    3 A 3,45 10
    2 B 6,97 12
    4 B 12 16
    is it possible to do this in sql? ( sql. 8.1)

    ... if your table does not contain exactly what you expect you could get:
    'single row sub-query returns more than one row'
    To prevent that, put a unique index on (name, version). If this combination is not always unique, you will need to cater for the possibility in the update statement.

  • Duplicate data in the same table

    Hi,
    I have one table like :
    bq. TABLE : \\ a1 azerty clavier \\ a2 toto1 voiture \\ ...
    I need to transform the table into something like this :
    bq. TABLE : \\ a1 azerty clavier \\ a2 toto1 voiture \\ b1 azerty clavier \\ b2 toto1 voiture \\ ...
    Do you know if is it possible to do this using a command or a script ?
    Regards

    user7224400 wrote:
    I have one table like :
    bq. TABLE : \\ a1 azerty clavier \\ a2 toto1 voiture \\ ...
    I need to transform the table into something like this :
    bq. TABLE : \\ a1 azerty clavier \\ a2 toto1 voiture \\ b1 azerty clavier \\ b2 toto1 voiture \\ ...
    Do you know if is it possible to do this using a command or a script ?
    - Where did you get "b1" and "b2" from ?
    - Why is it "b1" and "b2" and not something like, say, "p1", "p2" or "X1", "X2" ?
    - Is it because "b" follows "a" ? If you had "p1", "p2" instead of "a1", "a2", would you expect "q1", "q2" ?
    - What if you had "z1", "z2" instead of "a1", "a2" ? What would you expect instead of "b1", "b2" in that case ?
    - Are there numbers higher than 2 for "a" ? Do you want to derive corresponding rows with all such numbers suffixed to the next character after "a" (if that's what your logic is) ?
    isotope

Maybe you are looking for