How to compare records in the same table?

I have a table of course registrations.  I would like to select course registrations as of a certain date that do not have a dropped status against it.
CREATE TABLE REGISTRATIONS
(ID VARCHAR(7) ,
COURSE VARCHAR(4),
CURRENT_STATUS VARCHAR(10),
STATUS_DATE VARCHAR(10))
INSERT INTO REGISTRATIONS
(ID, COURSE, CURRENT_STATUS, STATUS_DATE)
VALUES
('1111111','ADMN', 'REGISTERED', '2014-04-10'),
('1111111','MATH', 'REGISTERED', '2014-04-10'),
('1111111','ADMN', 'DROPPED', '2014-04-10'),
('1111111','MATH', 'DROPPED', '2014-04-12'),
('1111111','BIOL', 'REGISTERED', '2014-04-10')
SELECT * FROM REGISTRATIONS
ORDER BY COURSE, CURRENT_STATUS
drop table REGISTRATIONS
ID COURSE CURRENT_STATUS STATUS_DATE
1111111 ADMN DROPPED 2014-04-10
1111111 ADMN REGISTERED 2014-04-10
1111111 BIOL REGISTERED 2014-04-10
1111111 MATH DROPPED 2014-04-12
1111111 MATH REGISTERED 2014-04-10
The above example shows that ID '1111111' has registered for ADMN and BIOL on April 10th but dropped ADMN the same day.  It also shows that they registered for MATH on April 10th but dropped it on the 12th.
If I were to select course registrations to date as of April 10 I would see both ADMN records, BIOL and MATH.  BIOL and MATH would be OK but I don't want to see the ADMN data in the result because they have essentially cancelled themselves out. 
In saying that, how do I write a script to select all course registrations as of a certain date but omit the ones that have been dropped at anytime before the select date?

check below,
SELECT * FROM REGISTRATIONS a
WHERE CURRENT_STATUS <> 'DROPPED' AND STATUS_DATE <= '2014-04-12'
AND COURSE NOT IN (
SELECT COURSE FROM REGISTRATIONS
WHERE CURRENT_STATUS = 'DROPPED' AND STATUS_DATE <= '2014-04-12')
ORDER BY a.COURSE, a.CURRENT_STATUS

Similar Messages

  • Duplicate records in the same table

    Hello.
    I want to duplicate records in the same table, changing just two date fields and id. Id is changed with sequence.
    Example:
    id name start_date end_date
    1 record_1 01.01.04 31.12.04
    2 record_2 01.01.03 31.12.03
    I want to duplicate record with the start_date year 04 and the duplicated record would change that start_date into year 05.
    After duplicate it should look like:
    1 record_1 01.01.04 31.12.04
    2 record_2 01.01.03 31.12.03
    3 record_1 01.01.05 31.12.05
    How should my insert look like?
    Thanks

    create sequence A_SEQ
       start with 3
       nocache
    insert into tableA
            (ID, name, start_date end_date)
       select
               A_SEQ.nextval   
              ,NAME
              ,start_date + add_months (12)
              ,end_date   + add_months (12)
         from
               tableA
        where
               start_date >= to_date('01.01.2004','dd.mm.yyyy')
          and  start_date <= to_date('01.01.2004','dd.mm.yyyy')

  • Master and Detail records in the same table

    Hi Steve,
    I have master and detail address records in the same table (self-reference). The master addresses are used as templates for detail addresses. Master addresses do not have any masters. Detail addresses have three masters: a master address, a calendar reference and a department. Addresses change from time to time and every department has its own email-account, but they refer to the same master to pre-fill some common values.
    Now I need to edit the master and detail address records on the same web page simultaneously.
    My question is: Can I implement a Master-View and Detail-View which refer to the same Entity-Object? Or should I implement a second Entity-Object? Or can it be done in a single Master-Detail-View?
    Thanks a lot.
    Kai.

    At a high level, wouldn't this be similar to an Emp entity based on the familiar EMP table that has an association from Emp to itself for the Emp.Mgr attribute?
    You can definitely build a view object that references two entity usages of the same entity like this to show, say, an employee's ENAME and at the same time their manager's ENAME.
    If there are multiple details for a given master, you can also do that with separate VO's both based on the same entity, sure. Again, just like a VO that shows a manager, and a view-linked VO of all the employees that report to him/her.

  • Comparing totals from the same table

    I am trying to compare data from the same table..
    i am using an alias of the table to set up the select but i am running into a cartesian set.
    I am comparing data (totals) from different dates from the same table ; i have included the query which is giving me a problem:
    select a.date_in,b.date_in,a.Table_name,
    DECODE(a.schema_name,
    'EZLIVE','ITP','EZAC','ACT','OTHER')AS DEPT,
    a.type,
    a.status,
    a.TOTAL,
    b.total
    from agg_results a,agg_results b
    where a.schema_name=b.schema_name
    and to_char(a.date_in,'mm/dd/yyyy')='&date_in'
    and to_char(b.date_in,'mm/dd/yyyy')='&date_in';
    any help thanks
    Ellery

    I think you need to join in-line views instead of the tables directly. something like:
    SELECT a.date_in,b.date_in,a.table_name,a.dept,a.type,a.status,a.total,b.total
    FROM (SELECT date_in,table_name,
                 DECODE(schema_name,'EZLIVE','ITP',
                                    'EZAC','ACT','OTHER') dept,
                 type,status,total
          FROM agg_results
          WHERE date_in = to_date('&date_in','mm/dd/yyyy') a,
         (SELECT date_in,table_name,
                 DECODE(schema_name,'EZLIVE','ITP',
                                    'EZAC','ACT','OTHER') dept,
                 type,status,total
          FROM agg_results
          WHERE date_in = to_date('&date_in','mm/dd/yyyy') b
    WHERE a.dept = b.deptTTFN
    John

  • 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 do I sum across the same table in multiple sheets?

    So I'm trying to figure out an annoying problem.
    I have a largish (100's) amount of data with each collection being a table in a sheet, one sheet per data collection. This means I have 100's of sheets, each with the same table name and layout. Each sheet has several hundred data points in it.
    How do I do a sum across all of the same table in all the sheets?
    For example I want to do Sum('Data Sheet Number *'::'Table 1'::A1) to get a sum of everything in all the A1 cells of all the sheets named 'Data Sheet Number ' followed by anything (I'm using the star in the same way one would do it in a shell...)
    Thanks!
    Message was edited by: unusedusername
    Message was edited by: unusedusername

    To respond to WWJD: I was handed the data and I don't have any control over it's format...
    I found the answer in the forums though, so I guess I'm answering my own question
    http://discussions.apple.com/thread.jspa?messageID=6203991&#6203991
    The auto-filling INDIRECT reference worked very well for me.

  • Compare several records in the same table

    Hello, i´m writing a BAT file so i can export some information that i query.
    I have a automatic integration that from time to time checks if there is any new client´s and generates a trigger.
    If an error ocurs i it will repeat the process until the client is in the database.
    I cannot create tables or modify structure.
    My problem is that i need to compare the most updated record with the field CLIENT_ID
    Let me give up an example:
    Table A
    CLIENT_ID CREATEDTIME ERROR_MESSAGE
    0 01-01-2009 Sucess
    1 01-01-2009 Error
    2 01-01-2009 Sucess
    1 02-01-2009 Sucess
    3 02-01-2009 Sucess
    4 02-01-2009 Error
    I need to compare client "1" created on 01-01-2009 that gived Error with all new records to see if is Sucess and my
    query should only return the client_ID "4" and export with sqlplus
    Could you please help me out?

    with my_tab as (select 0 client_id, to_date('01/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 1 client_id, to_date('01/01/2009', 'dd/mm/yyyy') createdtime, 'Error' error_message from dual union all
                    select 2 client_id, to_date('01/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 1 client_id, to_date('02/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 3 client_id, to_date('02/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 4 client_id, to_date('02/01/2009', 'dd/mm/yyyy') createdtime, 'Error' error_message from dual)
    -- end of test data set up to mimic a table called "my_tab"
    select client_id
    from   my_tab
    group by client_id
    having max(decode(error_message, 'Error', 1, 2)) = 1;should do what you want.
    Edited by: Boneist on 05-Jan-2009 16:06
    Hmm, not quite.... thinking of an amendment if the answer to BluShadow's question is Yes
    Aha,
    with my_tab as (select 0 client_id, to_date('01/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 1 client_id, to_date('01/01/2009', 'dd/mm/yyyy') createdtime, 'Error' error_message from dual union all
                    select 2 client_id, to_date('01/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 1 client_id, to_date('02/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 3 client_id, to_date('02/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 4 client_id, to_date('02/01/2009', 'dd/mm/yyyy') createdtime, 'Error' error_message from dual union all
                    select 1 client_id, to_date('03/01/2009', 'dd/mm/yyyy') createdtime, 'Error' error_message from dual)
    -- end of test data set up to mimic a table called "my_tab"
    select client_id
    from   my_tab
    group by client_id
    having max(decode(error_message, 'Error', 1, 2)) keep (dense_rank last order by createdtime) = 1;(which happens to be a more generalised form of what Frank's posted below!)

  • How to compare records in singe internal table

    Hi Folks,
    iam having 3 records in my first itab( T_FINAL) with fields
    material no,  descrip ,  mat type and  group.
    and 16 records in second itab(T_MVKE ) with fields
    mat no ,  distri.chanel  and division
    now I want to fetch the records from T_MVKE  by comparing the records in
    T_FINAL .my requirement is to check the given mat no. in sales org.2000,2100.  if yes then i have to consider 2000 only, if it is in only 2100 then consider 2100 only . is it is in 2000 only then consider 2100 only
    my code is
    LOOP AT T_FINAL.
        READ TABLE T_MVKE WITH KEY MATNR = T_FINAL-MATNR.
       IF SY-SUBRC = 0.
       ON CHANGE OF T_MVKE-MATNR OR T_MVKE-VKORG.
    IF T_MVKE-VKORG = '2000' and SY-TABIX > 1.
          CONCATENATE '2000' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.
    ELSEIF T_MVKE-VKORG = '2000' AND SY-TABIX = 1.
         CONCATENATE '2000' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.
    ELSE.
        CONCATENATE '2100' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.
        ENDIF.
    this logic fails ,. could tell me how to compare values in single itab?
    Thanks
    neha

    Hi ,
    if i've understand you correctly , try that:
    LOOP AT t_final.
      AT NEW matnr.
        CLEAR: v_2000, v_2100.
    *1) 2000
        READ TABLE  t_mvke    WITH KEY matnr = t_final-matnr
                                       vkorg = 2000.
        IF sy-subrc = 0.
          v_2000 = 'X'.
        ENDIF.
    *2) 2100
        READ TABLE  t_mvke    WITH KEY matnr = t_final-matnr
                                       vkorg = 2100.
        IF sy-subrc = 0.
          v_2100 = 'X'.
        ENDIF.
    *compare
        IF v_2000 = 'X' AND  v_2100 = 'X'.
    *read 2000 only
        ELSEIF v_2000 = ' '  AND v_2100 = ' '.
    *nothing found
        ELSE.
    *all other combinations
    *read 2100 only
        ENDIF.
      ENDAT.
    ENDLOOP.
    regards Andreas

  • How to insert record inside the internal table in below code

    Hi all,
    My requirement is to find the sub-total and need to insert in between the internal table.
    You can see the output ....where I want the sub-total F2 when 1 & 2 combindely , 3 , 4& 5 combindely .Please check it and let me know is it possible
    when i am using modification  it is not creating extra row inside the table instead it is modifying one row and putting the total there.
    For ex: the origianl output is
    F1   F2       F3
    A      1          1
    B      1          1
    F      2          1
    D      3          1
    E      4          1
    C      5          1
    We want to display all the total of f2 of 1-2 , 3 , 4-5
    so expcected output is
    F1   F2       F3
    A      1          1
    B      1          1
    F      2          1
         *              3  ->This is the sub-total of 1& 2 of f2
    D      3          1
            *           1 ->this is the sub-total of 3
    E      4          1
    C      5          1
          *             2 -> this is the sub-total of 4 & 5
    = space
    But coming output is
    A 1          1
    B 1          1
    *             3 -> it is modifying the F row and inserting the total .Total is comong correct but is shoule insert  instead of modifying the record!!
      *           1
    E  4          1
    *             2
    Please help how to insert the row total at the end of the chage of field
    Please find the below code ..Due to space problem i am attaching below
    Sas

    Here is the solution ....i Got the answer Thanks for your helping hands friends
    REPORT  YTEST_MODIFY.
    DATA: BEGIN OF ITAB OCCURS 1,
    TOT TYPE C,
    F1 TYPE C,
    F2 TYPE C,
    F3 TYPE I ,
    END OF ITAB.
    DATA: BEGIN OF JTAB OCCURS 1,
    F1 TYPE C,
    F2 TYPE C,
    F3 TYPE I ,
    END OF JTAB.
    START-OF-SELECTION.
      ITAB-F1 = 'A'.
      ITAB-F2 =  1.
      ITAB-F3 =  1.
      APPEND ITAB.
      ITAB-F1 = 'B'.
      ITAB-F2 =  1.
      ITAB-F3 =  1.
      APPEND ITAB.
      ITAB-F1 = 'C'.
      ITAB-F2 =  5.
      ITAB-F3 =  1.
      APPEND ITAB.
      ITAB-F1 = 'D'.
      ITAB-F2 =  3.
      ITAB-F3 =  1.
      APPEND ITAB.
      ITAB-F1 = 'E'.
      ITAB-F2 =  4.
      ITAB-F3 =  1.
      APPEND ITAB.
      ITAB-F1 = 'F'.
      ITAB-F2 =  2.
      ITAB-F3 =  1.
      APPEND ITAB.
      SORT ITAB BY F2.
      LOOP AT ITAB.
        WRITE:/1 ITAB-F1 ,
              8 ITAB-F2 ,
              10 ITAB-F3 .
      ENDLOOP.
      LOOP AT ITAB.
        IF ITAB-F2 = 1 OR ITAB-F2 = 2.
          ITAB-TOT = 1.
          MODIFY ITAB.
        ELSEIF ITAB-F2 = 3.
          ITAB-TOT = 3.
          MODIFY ITAB.
        ELSEIF ITAB-F2 = 4 OR ITAB-F2 = 5.
          ITAB-TOT = 4.
          MODIFY ITAB.
        ENDIF.
      ENDLOOP.
      SKIP 2.
      SORT ITAB BY TOT.
      DATA : L_SUM(2) TYPE C,
             L_ROW(2) TYPE C.
      LOOP AT ITAB.
        MOVE-CORRESPONDING ITAB TO JTAB.
        APPEND JTAB.
        L_SUM = L_SUM + ITAB-F3 .
        AT END OF TOT.
          CLEAR JTAB.
          JTAB-F3 = L_SUM .
          APPEND JTAB.
          CLEAR L_SUM.
        ENDAT.
      ENDLOOP.
      LOOP AT JTAB.
        WRITE:/1 JTAB-F1 ,
              8 JTAB-F2 ,
              10 JTAB-F3 .
      ENDLOOP.
    *  DATA: a TYPE i , b .
    *  LOOP AT itab.
    *    IF b = 0.
    *      a = a + itab-f3.
    *    ENDIF.
    *    AT END OF tot.
    *      MOVE space TO itab-f1.
    *      MOVE space TO itab-f2.
    *      MOVE a TO itab-f3.
    *      MODIFY itab .
    *      CLEAR a.
    *      b = 1.
    *    ENDAT.
    *    b = 0.
    *  ENDLOOP.
    *  LOOP AT itab.
    *    MOVE-CORRESPONDING itab TO jtab.
    *    APPEND jtab.
    *  ENDLOOP.
    *  ULINE.
    *  LOOP AT jtab.
    *    WRITE: / jtab-f1 , jtab-f2 , jtab-f3.
    *  ENDLOOP.

  • Two records from the same table in for loop

    I have a table that holds teams, a table that holds scores and a table that holds match data.
    I am finding it dificult to get the player data for the second team.
    Currently It is showing player information for one team.
    It does echo out the second team name, but not their player info.
    Can someone have a look at my code and make it work.
    I took off the code I had for the second team becuase it was ging me Error 1065
    Main Query:
    mysql_select_db($database_db, $db);
    $query_match_fixtures = "select m.match_id, date_format(m.date, '%d/%m/%Y') as mDate, m.time, t1.division, m.report, t1.team_name as team1_name, s1.score as score1, t2.team_name as team2_name, s2.score as score2
    from matches m left join (matchscores s1 left join team t1 on t1.team_id = s1.team) on (s1.match_id = m.match_id) left join (matchscores s2 left join team t2 on t2.team_id = s2.team) on (s2.match_id = m.match_id)
    where s1.team <> s2.team AND m.match_id = $matchID
    group by match_id
    order by m.match_id";
    $match_fixtures = mysql_query($query_match_fixtures, $db) or die(mysql_error());
    //$row_match_fixtures = mysql_fetch_assoc($match_fixtures);
    $totalRows_match_fixtures = mysql_num_rows($match_fixtures);
    Player extraction:
    mysql_select_db($database_db, $db);
    $row_match_player = array();
    for ($i = 0; $i < $totalRows_history; $i++)
        $row_history[$i] = mysql_fetch_assoc($history);
    for ($i = 0; $i < $totalRows_match_fixtures; $i++)
        $row_match_fixtures[$i] = mysql_fetch_assoc($match_fixtures);
        $match_player_query = "SELECT *
                               FROM match_player
                                LEFT JOIN player on player.player_id = match_player.player_id
                                LEFT JOIN team ON player.team_id = team.team_id
                               WHERE match_id = ".$matchID."
                                AND team.team_name = '".$row_match_fixtures[$i]['team1_name']."'";
        $result_match_player = mysql_query($match_player_query, $db) or die("large error ".mysql_errno());
        $totalRows_match_player = mysql_num_rows($result_match_player);
        for ($r; $r < $totalRows_match_player; $r++)
            $temp_row_match_player[$r] = mysql_fetch_assoc($result_match_player);
        array_push($row_match_player, $temp_row_match_player);
    The display table:
            <div class="tableHeading">
            <h2><?php echo $row_history['mDate']; ?></h2>
            </div>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="25" bgcolor="#000000"><div align="left" style="color:#FFFFFF"><strong>Type</strong></div></td>
        <td height="25" bgcolor="#000000"><div align="left" style="color:#FFFFFF"><strong>Home</strong></div></td>
        <td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Score</strong></div></td>
        <td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Away</strong></div></td>
        <td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Kick-Off</strong></div></td>
        <td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Venue</strong></div></td>
        <td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Referee</strong></div></td>
      </tr>
      <tr>
        <?php foreach ($row_match_fixtures as $show_match_fixtures)
        { ?>
            <td height="25" bgcolor="#dfdfdf">
            <div align="left"><?php echo $show_match_fixtures['division']; ?></div>
            </td>
            <td height="25" bgcolor="#dfdfdf">
            <div align="left"><?php echo $show_match_fixtures['team1_name']; ?></div>
            </td>
            <td height="25" bgcolor="#dfdfdf">
            <div align="center"><?php echo $show_match_fixtures['score1']; ?> - <?php echo $show_match_fixtures['score2']; ?></div>
            </td>
            <td height="25" bgcolor="#dfdfdf">
            <div align="center"><?php echo $show_match_fixtures['team2_name']; ?></div>
            </td>
            <td height="25" bgcolor="#dfdfdf">
            <!-- You do not want a nested loop inside the header so these results will have to go inside the table-->
            <div align="center"><?php echo $row_history['time']; ?></div>
            </td>
            <td height="25" bgcolor="#dfdfdf">
            <div align="center"><?php echo $row_history['venue_name']; ?></div>
            </td>
            <td height="25" bgcolor="#dfdfdf">
            <div align="center"><?php echo $row_history['fname']; ?> <?php echo $row_history['sname']; ?></div>
            </td>
        </tr>
          <tr>
            <?php foreach ($row_match_player as $player_array)
                   foreach ($player_array as $player_display)
            ?>
            <td valign="top">Goalscorers</td>     
            <td>
              <?php echo $player_display['fname']." ".$player_display['sname']." (".$player_display['Goals']; ?>)<br />
            </td>
            <td> </td>
            <td>
              <?php echo $player_display['fname']." ".$player_display['sname']." (".$player_display['Goals']; ?>)<br />
            </td>
            <td> </td>
            <td> </td>
            <td> </td>
          </tr>
          <tr>
            <td valign="top">Yellow Cards</td>
            <td><?php echo $player_display['YC']; ?></td>
            <td> </td>
            <td><?php echo $player_display['YC']; ?></td>
            <td> </td>
            <td> </td>
            <td> </td>
          </tr>
          <tr>
            <td valign="top">Red Cards</td>
            <td><?php echo $player_display['RC']; ?></td>
            <td> </td>
            <td><?php echo $player_display['RC']; ?></td>
            <td> </td>
            <td> </td>
            <td> </td>
          </tr>
          <tr>
            <td valign="top">Man of the Match</td>
            <td><?php echo $player_display['fname']; ?> <?php echo $player_display['sname']; ?></td>
            <td> </td>
            <td><?php echo $player_display['fname']; ?> <?php echo $player_display['sname']; ?></td>
            <td> </td>
            <td> </td>
            <td> </td>
          </tr>
                <?php
                    }// close and unset $player_display
                    unset($player_display);
                } //close and unset $player_array
            unset($player_array);
         } //close and unset $show_match_fixtures
        unset($show_match_fixtures);?>
    </table>
    As you can see from  the picture above the table is displayed with the name of the "goal  scorer" for that team under (home) or Home team
    When I try to create the same thing for away team I get a error, either a syntax error or 1065.
    I tried having a foreach do two queries but that did not work.
    Any help would be appriecated

    I did try that, but I have messed it up.
    Now the team names do not display at the top of the table.

  • Create a query to compare values from the same table

    Suppose you have the below table, same ID's occur for same month as well as different month
    ID Month Value
    226220      201203     100
    1660      201204     200
    26739      201204     1010
    7750     201205     31.1
    I need a query to determine the below laid result
    ID Month Prior_month_value Prior_Month Value
    1234 201203 10 201201 100
    3456 201206 56.1 201204 78
    Please help
    Edited by: Jaguar on Jul 10, 2012 3:00 AM

    As mentioned, you can use the analytical function lag...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 226220 as id, 201203 as mnth, 100 val from dual union all
      2             select 1660, 201204, 200 from dual union all
      3             select 226220, 201204, 1010 from dual union all
      4             select 1660, 201206, 31.1 from dual union all
      5             select 7750, 201205, 60 from dual)
      6  --
      7  -- end of test data
      8  --
      9  select id
    10        ,mnth
    11        ,val
    12        ,lag(mnth) over (partition by id order by mnth) as prev_month
    13        ,lag(val) over (partition by id order by mnth) as prev_val
    14  from t
    15* order by id, mnth
    SQL> /
            ID       MNTH        VAL PREV_MONTH   PREV_VAL
          1660     201204        200
          1660     201206       31.1     201204        200
          7750     201205         60
        226220     201203        100
        226220     201204       1010     201203        100Edit to Add...
    and to filter out just the ones where there is a previous month...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 226220 as id, 201203 as mnth, 100 val from dual union all
      2             select 1660, 201204, 200 from dual union all
      3             select 226220, 201204, 1010 from dual union all
      4             select 1660, 201206, 31.1 from dual union all
      5             select 7750, 201205, 60 from dual)
      6  --
      7  -- end of test data
      8  --
      9  select id, mnth, val, prev_month, prev_val
    10  from (
    11        select id
    12              ,mnth
    13              ,val
    14              ,lag(mnth) over (partition by id order by mnth) as prev_month
    15              ,lag(val) over (partition by id order by mnth) as prev_val
    16        from t
    17       )
    18  where prev_month is not null
    19* order by id, mnth
    SQL> /
            ID       MNTH        VAL PREV_MONTH   PREV_VAL
          1660     201206       31.1     201204        200
        226220     201204       1010     201203        100Edited by: BluShadow on 10-Jul-2012 11:32

  • How to compare record count of two tables?

    Hi,
    i am in need of simple sql script where i can compare two table record count.
    i have something like below:
    (select count(*) from table1) minus (select count(*) from table2)
    now the problem is if the table1 count greater then table2 count the output is fine.
    If the table2 record count is more then i am getting zero as the output.
    how can i get the difference in two tables record count?
    Thanks a lot in advance.
    --Raman.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Doing a MINUS between the counts does not yield the diff.
    e.g. if table A has 100 records and table B has 70 records then,
    SELECT count(*) FROM A
    minus
    SELECT count(*) from B
    will give 100 and not 30.
    Try this:
    SELECT (
    CASE WHEN ((select count(*) cnt from A) - (select count(*) cnt from B)) <0
    THEN ((select count(*) cnt from A) - (select count(*) cnt from B))* -1
    ELSE ((select count(*) cnt from A) - (select count(*) cnt from B)) END) Difference
    FROM dualor this is simpler
    SELECT abs(((select count(*) cnt from A) - (select count(*) cnt from B))) difference FROM dualEdited by: Caitanya on Jan 9, 2009 7:12 AM
    Applied abs function after seeing BluShadow's post :)

  • Insert New Records to the same table based on an existing record

    How do I write a query to get the output shown in the OutputTable?  Salary in OutputTable  = TableA.Salary * TableB.SCode
    I posted a similar question earlier but no solution, so, I've decided to use a different approach to get it done.
    TableA
    EmpId
    FName
    LName
    EType
    ECat
    Salary
    1
    John
    Doe
    Perm
    E
    100
    3
    Jane
    Jones
    Perm
    E
    150
    4
    Mike
    Moses
    Cont
    C
    50
    7
    Eric
    Holder
    Cont
    C
    75
    9
    Pete
    Pan
    Perm
    E
    60
    TableB
    EmpId
    ECat
    SCode
    1
    L
    2
    2
    L
    5
    3
    L
    5
    4
    L
    10
    5
    L
    7
    OutputTable
    EmpId
    FName
    LName
    EType
    ECat
    Salary
    1
    John
    Doe
    Perm
    E
    100
    3
    Jane
    Jones
    Perm
    E
    150
    4
    Mike
    Moses
    Cont
    C
    50
    7
    Eric
    Holder
    Cont
    C
    75
    9
    Pete
    Pan
    Perm
    E
    60
    1
    John
    Doe
    Manual
    E
    200
    3
    Jane
    Jones
    Manual
    C
    750
    4
    Eric
    Holder
    Manual
    C
    500

    The first line of your code; is the syntax correct?
    INSERT TableA
    yes
    so far as table structure matches with the source you dont need a column list
    Just use destination table name instead
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Findout the record in the same table

    Hi dear
    i have attendance table which have following columns
    CO_CODE NOT NULL VARCHAR2(2)
    CARD_NO NOT NULL VARCHAR2(6)
    PERIOD NOT NULL VARCHAR2(6)
    ATTEN_DATE NOT NULL DATE
    TIME_IN NOT NULL DATE
    TIME_OUT DATE
    BREAK_CODE NOT NULL NUMBER(1)
    in the table break_code = 2 its mean 'lunch break'
    and break_code = 3 its mean 'out door duty'
    break_code = 1 its meaning 'duty off'
    card_no period date time_in time_out break_code
    000220 200801 01-JAN-08 08:00 16:30 1
    000220 200801 02-JAN-08 08:01 09:30 3
    000220 200801 02-JAN-08 14:25 16:30 1
    000220 200801 03-JAN-08 08:00 08:45 3
    000220 200801 03-JAN-08 10:10 16:30 1
    000220 200801 04-JAN-08 08:00 16:30 1
    i just find the records which date have break_code and also duty off.
    please send us the query
    result will be as
    000220 200801 02-JAN-08 08:01 09:30 3
    000220 200801 02-JAN-08 14:25 16:30 1
    000220 200801 03-JAN-08 08:00 08:45 3
    000220 200801 03-JAN-08 10:10 16:30 1
    an early response will be highly appreciated.
    thanks
    regards
    abid

    1 = duty off
    3 = out door duty (perform duty out side the plant)
    I just select those records which card have two rows and break_code (1,3).
    CARD_N PERIOD ATTEN_DAT TIME_IN TIME_out BREAK_CODE
    000220 200801 01-JAN-08 08:00     16:33 1
    000220 200801 02-JAN-08 08:02      11:00 3
    000220 200801 02-JAN-08 12:53      16:32 1
    000220 200801 03-JAN-08 07:49      10:18 3
    000220 200801 03-JAN-08 11:12      16:33 1
    000521 200801 04-JAN-08 07:57      16:34 1
    000521 200801 05-JAN-08 07:56      10:38 3
    000521 200801 05-JAN-08 11:59      16:34 1
    000521 200801 07-JAN-08 08:00      08:31 3
    000521 200801 07-JAN-08 10:08      16:36 1
    000521 200801 08-JAN-08 08:00      09:36 3
    000521 200801 08-JAN-08 11:10      16:37 1
    000526 200801 09-JAN-08 08:00      10:20 3
    000526 200801 09-JAN-08 11:57      16:33 1
    000526 200801 10-JAN-08 08:21      16:34 1
    000526 200801 11-JAN-08 08:05      10:26 3
    000526 200801 11-JAN-08 11:34      12:37 2
    000526 200801 11-JAN-08 13:35      16:35 1
    000526 200801 12-JAN-08 08:00      09:02 3
    000526 200801 12-JAN-08 09:52      16:36 1
    000542 200801 14-JAN-08 07:50      16:35 1
    000542 200801 15-JAN-08 07:59      10:20 3
    000542 200801 15-JAN-08 12:17      16:32 1
    000542 200801 16-JAN-08 07:52      10:34 3
    000542 200801 16-JAN-08 11:40      16:35 1
    000542 200801 17-JAN-08 07:53      16:35 1
    000513 200801 18-JAN-08 07:59      16:35 1
    000513 200801 21-JAN-08 07:54      10:47 3
    000513 200801 21-JAN-08 11:52      16:33 1
    000513 200801 22-JAN-08 07:54      09:35 3
    000513 200801 22-JAN-08 10:36      16:31 1
    000520 200801 23-JAN-08 07:52      11:15 3
    000520 200801 23-JAN-08 11:55      16:32 1
    000520 200801 24-JAN-08 08:04      10:54 3
    000520 200801 24-JAN-08 12:27      16:32 1
    000520 200801 25-JAN-08 08:04      16:33 1
    000520 200801 26-JAN-08 07:51      10:15 3
    my result should be.
    CARD_N PERIOD ATTEN_DAT TIME_IN TIME_out BREAK_CODE
    000220 200801 02-JAN-08 08:02      11:00 3
    000220 200801 02-JAN-08 12:53      16:32 1
    000220 200801 03-JAN-08 07:49      10:18 3
    000220 200801 03-JAN-08 11:12      16:33 1
    000521 200801 05-JAN-08 07:56      10:38 3
    000521 200801 05-JAN-08 11:59      16:34 1
    000521 200801 07-JAN-08 08:00      08:31 3
    000521 200801 07-JAN-08 10:08      16:36 1
    000521 200801 08-JAN-08 08:00      09:36 3
    000521 200801 08-JAN-08 11:10      16:37 1
    000526 200801 09-JAN-08 08:00      10:20 3
    000526 200801 09-JAN-08 11:57      16:33 1
    000526 200801 11-JAN-08 08:05      10:26 3
    000526 200801 11-JAN-08 11:34      12:37 2
    000526 200801 11-JAN-08 13:35      16:35 1
    000526 200801 12-JAN-08 08:00      09:02 3
    000526 200801 12-JAN-08 09:52      16:36 1
    000542 200801 15-JAN-08 07:59      10:20 3
    000542 200801 15-JAN-08 12:17      16:32 1
    000542 200801 16-JAN-08 07:52      10:34 3
    000542 200801 16-JAN-08 11:40      16:35 1
    000513 200801 21-JAN-08 07:54      10:47 3
    000513 200801 21-JAN-08 11:52      16:33 1
    000513 200801 22-JAN-08 07:54      09:35 3
    000513 200801 22-JAN-08 10:36      16:31 1
    000520 200801 23-JAN-08 07:52      11:15 3
    000520 200801 23-JAN-08 11:55      16:32 1
    000520 200801 24-JAN-08 08:04      10:54 3
    000520 200801 24-JAN-08 12:27      16:32 1

Maybe you are looking for

  • HP deskjet F370 driver for windows 8

    I don't seem to be able to find a driver for Windows 8.1 that will allow me to use my HP Deskjet F370. Can anybody give me advice? This question was solved. View Solution.

  • What WordStar 3.01 can do in Mail Merge that Pages '09 can't.

    I have a Bento database. I want to print contra dances from it on 3x5 index cards. I can save the database as a Numbers worksheet with all the data I want on it. I SHOULD be able to use the fields from that Numbers file to create a Pages document tha

  • Windows 7 claiming it's not genuine

    I re-installed my Windows 7 Home Premium operating system. After a couple of weeks it started to claim that my Windows wasn't genuine. My operating came with the computer and now it doesen't approve my activation code. And I really don't know what to

  • LM24. Enter Button does not work

    Hi. I'm trying to pack a delivery via RF. I'm using the LM61 transaction put the Delivery number -  Enter - F9 - It takes me to the LM24 transaction with the Pos. 916 and Number of Delivery - F4 to pack it by material. and I type the Material Pack Nu

  • EX60 configuration with Call Manager 9.1

    Dear All, I am running CUCM 9.1 I have an EX60 Device which i need to register with call manager 9.1 Please provide the steps to perform this task and bring it into a working condition Will be thankful for your response. Regards, Malik.