SQL selecting group by but....

select count(empno) as total,dept from emp group by dept
total | dept
4 | 10
3 | 20
5 | 30
i want an another field with this to give me like this
employee_ _ Number|total | dept
121,122,123,124_ _ | 4 | 10
125,126,127_ _ _ _ | 3 | 20
129,130,131,132,133| 5 | 30
means i need list of empno seperated by comma with each group

Hi,
Fakhr-e-Alam wrote:
is there any built in function which give me
1-upto-4, 11-upto-14, 33,35, 40-upto-41....
instead of
1,2,3,4, 11,12,13,14, 33,35, 40,41...There's no single function that will take a set of 12 rows (or a list of 12 comma-separated items) such as 1,2,3,4, 11,12,13,14, 33,35, 40,41 and return a set of 5 rows (or items) like 1-upto-4, 11-upto-14, 33,35, 40-upto-41.
You can do it with various combinations of anlayitic and aggreagate functions.
If you'd like help, post CREATE TABLE and INSERT statements for your sample data, and the results you want from that data. Say whatever you know about the starting data. (For example, are the numbers distinct? Are they always integers?)
If you can show your problem using commonly available tables (like those in the scott schema), then you don't have to post any sample data; just the results, and an explanation of how you get those results from that data.
Always say which version of Oracle you're using.

Similar Messages

  • SQL select group by Query

    Suppose a table T1 has 2 columns C1 and C2 and data as follows:
    C1 C2
    == ==
    1 A1
    1 A2
    2 B1
    2 B2
    2 B3
    3 C1
    4 D1
    4 D2
    I want to write a SQL query to select data and display as follows (i.e. grouped by C1, but C2 should display as single field with say '-' seperator):
    C1 C2-Details
    == ========
    1 A1-A2
    2 B1-B2-B3
    3 C1
    4 D1-D2
    Please help.
    Thanks in advance
    Goli

    Your query maybe like this
    SELECT c1,
    LTRIM(MAX(SYS_CONNECT_BY_PATH(c2,'-'))
    KEEP (DENSE_RANK LAST ORDER BY curr),'-') AS employees
    FROM (SELECT c1,
    c2,
    ROW_NUMBER() OVER (PARTITION BY c1 ORDER BY c2) AS curr,
    ROW_NUMBER() OVER (PARTITION BY c1 ORDER BY c2) -1 AS prev
    FROM t1)
    GROUP BY c1
    CONNECT BY prev = PRIOR curr AND c1 = PRIOR c1
    START WITH curr = 1;

  • SQL Select grouping by value

    Hi ,
    I have an output after a join statement and i have output
    which is like below.
    I have an output containing two colums with same data except for the emp_depts and would like to write a select statement which will give a single row as opposed to two rows as below.
    Current out put view.
    emp_no emp_Name emp_Depts
    1 Test HR
    1 Test Finance
    Desired output.
    1 Test HR,Finance
    Can some one please help.

    If you are on 10g:
    SQL> create table mytable
      2  as
      3  select 1 emp_no, 'Test' emp_Name, 'HR' emp_Depts from dual union all
      4  select 1, 'Test', 'Finance' from dual
      5  /
    Tabel is aangemaakt.
    SQL> with t as
      2  ( select emp_no,emp_name,substr(ed,2) emp_depts,rn
      3      from mytable
      4     model
      5           partition by (emp_no,emp_name)
      6           dimension by (row_number() over (partition by emp_no order by null) rn)
      7           measures (cast(emp_depts as varchar2(50)) ed)
      8           rules
      9           ( ed[any] order by rn desc = ed[cv()+1] || ',' || ed[cv()]
    10           )
    11  )
    12  select emp_no
    13       , emp_name
    14       , emp_depts
    15    from t
    16   where rn = 1
    17  /
        EMP_NO EMP_ EMP_DEPTS
             1 Test HR,Finance
    1 rij is geselecteerd.And this technique is not called pivoting, but string aggregation. If you search for this term you will see some other techniques as well.
    Regards,
    Rob.

  • I need to Sync/change my iPhone contacts but I can't select "Selected Groups"...?

    I need to Sync/change my iPhone contacts but I can't select "Selected Groups"...?

    This is what worked for me. Turned off icloud on iphone and computer. Logged into my icloud account at icloud.com via my web browser and deleted all of my contacts and calendars. I was then able to select selected contacts and selected calendars in iTunes.

  • Sql select query problem

    hi friends,
    i've a view called "risk_efforts" with fields user_id,user_name,wknd_dt,week_day,prod_efforts,unprod_efforts.
    Name Type
    ROW_ID NUMBER
    USER_ID VARCHAR2(14)
    USER_NAME VARCHAR2(50)
    WKND_DT VARCHAR2(8)
    WEEK_DAY VARCHAR2(250)
    PROD_EFFORTS NUMBER
    UNPROD_EFFORTS NUMBER
    data is like this:
    when there is some data in prod_efforts, unprod_efforts will be null
    when there is some data in unprod_efforts, prod_efforts will be null
    for example:
    USER_ID     USER_NAME     WKND_DT     WEEK_DAY     PROD_EFFORTS     UNPROD_EFFORTS
    G666999     GTest     20100403     TUE     null 3
    G666999     GTest     20100403     TUE     14     null
    now i want to combine these 2 rows into 1 row i.e o/p should be like this
    USER_ID     USER_NAME     WKND_DT     WEEK_DAY     PROD_EFFORTS     UNPROD_EFFORTS
    G666999     GTest     20100403     TUE     14 3
    i've tried all combinations but couldn't get the query. Please help me with the exact SQL select query.
    thanks,
    Girish

    Welcome to the forum.
    First read this:
    Urgency in online postings
    Secondly, it's always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
    You have provided #3 and #4. However with no usable form of sample data forum members will often not respond as quickly as they could if you provided #2.
    I'm just wagering a guess here but what about this:SELECT ROW_ID
    , USER_ID
    , WKND_DT
    , WEEK_DAY
    , MAX(PROD_EFFORTS) AS PROD_EFFORTS
    , MAX(UNPROD_EFFORTS) AS UNPROD_EFFORTS
    FROM RISK_EFFORTS
    GROUP BY ROW_ID
    , USER_ID
    , WKND_DT
    , WEEK_DAY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Oracle's SQL select should have a syntax like this

    Oracles SQL is very powerful but lacks a basic thing the LIMIT and OFFSET syntax which
    is present in postgres sql, I recommend oracle to support this syntax in future release.
    more details of this syntax can be found at :
    http://www.postgresql.org/idocs/index.php?sql-select.html
    SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
    * | expression [ AS output_name ] [, ...]
    [ FROM from_item [, ...] ]
    [ WHERE condition ]
    [ GROUP BY expression [, ...] ]
    [ HAVING condition [, ...] ]
    [ { UNION | INTERSECT | EXCEPT } [ ALL ] select ]
    [ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ]
    [ FOR UPDATE [ OF tablename [, ...] ] ]
    [ LIMIT { count | ALL } ]
    [ OFFSET start ]

    I've executed the above queries against my table and the results follows :
    The structure of the table
    Name Null? Type
    FATWAID NOT NULL NUMBER(11)
    FATWASTATUS NUMBER(1)
    SUBJ_NO NUMBER(4)
    LANG CHAR(1)
    SCHOLAR NUMBER(2)
    REVIEWER NUMBER(2)
    AUDITOR NUMBER(2)
    PUBLISHER NUMBER(2)
    SUBSCRIBER NUMBER(2)
    ENTRY NUMBER(2)
    FATWATITLE VARCHAR2(100)
    FATWATEXT CLOB
    FATWADATE DATE
    TRANSLATE CHAR(1)
    SELECTED NUMBER(1)
    SUBJ_MAIN NUMBER(4)
    I have set timing on and executed each query above, following are the statistics.
    First the number of rows in the table.
    SQL>set timing on
    SQL>select count (*) from fatwa;
    COUNT(*)
    1179651
    Elapsed: 00:00:13.05
    The query of Andrew Clarke
    SQL>SELECT fatwaid FROM (SELECT fatwaid, rownum as ranking FROM fatwa) r
    WHERE r.ranking BETWEEN &OFFSET AND &LIMIT
    SQL>/
    Enter value for offset: 100000
    Enter value for limit: 100009
    old 2: WHERE r.ranking BETWEEN &OFFSET AND &LIMIT
    new 2: WHERE r.ranking BETWEEN 100000 AND 100009
    FATWAID
    96592
    96593
    96594
    96595
    96596
    96597
    96598
    96599
    96600
    96601
    10 rows selected.
    Elapsed: 00:00:12.02
    SQL> /
    Enter value for offset: 1000000
    Enter value for limit: 1000009
    old 2: WHERE r.ranking BETWEEN &OFFSET AND &LIMIT
    new 2: WHERE r.ranking BETWEEN 1000000 AND 1000009
    FATWAID
    994621
    994622
    994623
    994624
    994625
    994626
    995769
    995770
    995771
    995772
    10 rows selected.
    Elapsed: 00:00:12.00
    The response time is decreasing because of use of bind variables,
    but 12 seconds is a sign of poor performance.
    Now a slight modification to Clarke's query
    I will add order by clause
    SQL> ed
    Wrote file afiedt.buf
    1 SELECT fatwaid FROM (SELECT fatwaid, rownum as ranking FROM fatwa ORDER BY fatwaid) r
    2* WHERE r.ranking BETWEEN &OFFSET AND &LIMIT
    SQL> /
    Enter value for offset: 100001
    Enter value for limit: 100010
    old 2: WHERE r.ranking BETWEEN &OFFSET AND &LIMIT
    new 2: WHERE r.ranking BETWEEN 100001 AND 100010
    FATWAID
    100032
    100033
    100034
    100035
    100036
    100037
    100038
    100039
    100040
    100041
    10 rows selected.
    Elapsed: 00:00:04.00 -- time reduced from 12 to 4 seconds
    A time of 4 seconds is acceptable but not good,
    response time should be in milli seconds.
    SQL> /
    Enter value for offset: 1000001
    Enter value for limit: 1000010
    old 2: WHERE r.ranking BETWEEN &OFFSET AND &LIMIT
    new 2: WHERE r.ranking BETWEEN 1000001 AND 1000010
    FATWAID
    1000032
    1000033
    1000034
    1000035
    1000036
    1000037
    1000038
    1000039
    1000040
    1000041
    10 rows selected.
    Elapsed: 00:00:03.09 -- this reduction is because of bind variables
    The query of Chris Gates
    SQL>select fatwaid
    2 from ( select a.*, rownum r
    3 from ( select *
    4 from fatwa
    5 --where x = :host_variable
    6 order by fatwaid ) a
    7 where rownum < &HigerBound )
    8 where r > &LowerBound
    SQL> /
    Enter value for higerbound: 100011
    old 7: where rownum < &HigerBound )
    new 7: where rownum < 100011 )
    Enter value for lowerbound: 100000
    old 8: where r > &LowerBound
    new 8: where r > 100000
    FATWAID
    100032
    100033
    100034
    100035
    100036
    100037
    100038
    100039
    100040
    100041
    10 rows selected.
    Elapsed: 00:00:02.04
    This seems to be fast
    SQL> /
    Enter value for higerbound: 1000011
    old 7: where rownum < &HigerBound )
    new 7: where rownum < 1000011 )
    Enter value for lowerbound: 1000000
    old 8: where r > &LowerBound
    new 8: where r > 1000000
    FATWAID
    1000032
    1000033
    1000034
    1000035
    1000036
    1000037
    1000038
    1000039
    1000040
    1000041
    10 rows selected.
    Elapsed: 00:01:14.02
    but this is worst when upper bound is 1 million.
    Finally Myers query
    SQL> select fatwaid from
    2 (select /*+ INDEX(fawtaid pk_fatwa) */ fatwaid, rownum x from fatwa
    3 where rownum < &UpperBound )
    4 where x > &LowerBound;
    Enter value for upperbound: 100011
    old 3: where rownum < &UpperBound )
    new 3: where rownum < 100011 )
    Enter value for lowerbound: 100000
    old 4: where x > &LowerBound
    new 4: where x > 100000
    FATWAID
    122418
    122419
    122420
    122421
    122422
    122423
    122424
    122425
    122426
    122427
    10 rows selected.
    Elapsed: 00:00:00.03 -- too fast
    SQL> /
    Enter value for upperbound: 1000011
    old 3: where rownum < &UpperBound )
    new 3: where rownum < 1000011 )
    Enter value for lowerbound: 1000000
    old 4: where x > &LowerBound
    new 4: where x > 1000000
    FATWAID
    984211
    984212
    984213
    984214
    984215
    984216
    984217
    984218
    984219
    984220
    10 rows selected.
    Elapsed: 00:00:02.02 -- with 1 million rows also satisfactory but it is not is milliseconds
    The same query after using order by clause
    SQL> select fatwaid from
    2 (select /*+ INDEX(fawtaid pk_fatwa) */ fatwaid, rownum x from fatwa
    3 where rownum < &UpperBound ORDER BY fatwaid)
    4 where x > &LowerBound;
    Enter value for upperbound: 100011
    old 3: where rownum < &UpperBound ORDER BY fatwaid)
    new 3: where rownum < 100011 ORDER BY fatwaid)
    Enter value for lowerbound: 100000
    old 4: where x > &LowerBound
    new 4: where x > 100000
    FATWAID
    100032
    100033
    100034
    100035
    100036
    100037
    100038
    100039
    100040
    100041
    10 rows selected.
    Elapsed: 00:00:00.06
    SQL> /
    Enter value for upperbound: 1000011
    old 3: where rownum < &UpperBound ORDER BY fatwaid)
    new 3: where rownum < 1000011 ORDER BY fatwaid)
    Enter value for lowerbound: 1000000
    old 4: where x > &LowerBound
    new 4: where x > 1000000
    FATWAID
    1000032
    1000033
    1000034
    1000035
    1000036
    1000037
    1000038
    1000039
    1000040
    1000041
    10 rows selected.
    Elapsed: 00:00:07.03 -- slow
    SQL> /
    Enter value for upperbound: 1000011
    old 3: where rownum < &UpperBound ORDER BY fatwaid)
    new 3: where rownum < 1000011 ORDER BY fatwaid)
    Enter value for lowerbound: 1000000
    old 4: where x > &LowerBound
    new 4: where x > 1000000
    FATWAID
    1000032
    1000033
    1000034
    1000035
    1000036
    1000037
    1000038
    1000039
    1000040
    1000041
    10 rows selected.
    Elapsed: 00:00:00.06
    when I execute the same query again it is bringing records from
    the SGA so it is very fast
    Now which one to choose from ?
    Andrew and Myers queries are good and currently I am using
    Myers query.
    There should be some technique to do this in the most efficient way.
    any input is appreciated.

  • Can we convert a SQL (Select Statement) to Procedure.?

    Hi
    I am using a select sql for retrieving the results - Below is a sample sql select query.
    select TableC.DATEFIELD as QUERY_DATE,
    TableB.COLUMN1 PROCESS,
    TableC.COLUMN1 PRODUCT,
    sum(TableC.COLUMN4) as OPEN_INSTANCES
    from      TableA, TableB, TableC
    where TableB.COLUMN1      = TableA.COLUMN2
    and      TableA.COLUMN2      = TableC.COLUMN2
    and      DATEFIELD <= to_date('2011-02-02' ,'YYYY-MM-DD')
    and      DATEFIELD >= to_date('2011-02-02' ,'YYYY-MM-DD')
    and      TableC.COLUMN4 <= (24 * 3600 )
    and      TableB.COLUMN1 like 'PROCESSID'
    and      TableC.COLUMN1 in ('OSRCITR')
    group by TableC.DATEFIELD as QUERY_DATE,
    TableA.COLUMN1 PROCESS,
    TableC.COLUMN1 PRODUCT
    I believe if we use a Procedure, It would be much faster. Is there any way that we can convert the above select sql to a procedure. If yes, how can it be.
    Thanks in Advance.
    -Sreekant

    Sreekant wrote:
    select TableC.DATEFIELD as QUERY_DATE,
    TableB.COLUMN1 PROCESS,
    TableC.COLUMN1 PRODUCT,
    sum(TableC.COLUMN4) as OPEN_INSTANCES
    from      TableA, TableB, TableC
    where TableB.COLUMN1      = TableA.COLUMN2
    and      TableA.COLUMN2      = TableC.COLUMN2
    and      DATEFIELD <= to_date('2011-02-02' ,'YYYY-MM-DD')
    and      DATEFIELD >= to_date('2011-02-02' ,'YYYY-MM-DD')
    and      TableC.COLUMN4 <= (24 * 3600 )
    and      TableB.COLUMN1 like 'PROCESSID'
    and      TableC.COLUMN1 in ('OSRCITR')
    group by TableC.DATEFIELD as QUERY_DATE,
    TableA.COLUMN1 PROCESS,
    TableC.COLUMN1 PRODUCT
    I believe if we use a Procedure, It would be much faster. Is there any way that we can convert the above select sql to a procedure. If yes, how can it be.Using the code tags would make the query easier to read :)
    What version of Oracle are you on?
    Under the right conditions deconstructing a huge query into smaller components sometimes can offer performance increases, but this is more true of older versions of Oracle than recent ones. Lately I get better results from tuning queries in place - as Aman pointed out you introduce context switching (moving between the SQL and PL/SQL engines to do work) which can also hurt performance.
    Try tuning the query first. Get an execution plan. Things you can look for include
    * make sure the driving table is the best one
    * are the join columns properly indexed? Are existing indexes being suppressed due to the functions?
    Is "and      TableB.COLUMN1 like 'PROCESSID' " correct? without a wildcard LIKE should evalate to =

  • Querying Data w PL/SQL - selecting 1 row

    Initial research done at:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#i45320
    Querying Data with PL/SQL - Selecting At Most One Row: SELECT INTO Statement
    I am trying to run a simple SELECT COUNT statement in PL/SQL. Can someone please help me with the syntax? Here is my SQL select count(*) statement.
    SELECT ITEM_TYPE, count(*)
    FROM
    APPLSYS.WF_ITEMS
    WHERE
    ITEM_TYPE = 'GLBATCH' AND
    END_DATE is not null
    GROUP BY ITEM_TYPE;
    Thanks, I tried following some examples found on these forum threads but couldn't seem to find one for something so basic as this.

    I am trying to run a simple SELECT COUNT statement in PL/SQL. Can someone please help me with the syntax?in plsql you would declare variables to hold the selected values:
    declare
       l_item_type   applsys.wf_items.item_type%type;
       l_cnt         integer;
    begin
         select   item_type, count ( * )
           into   l_item_type, l_cnt
           from   applsys.wf_items
          where   item_type = 'GLBATCH' and end_date is not null
       group by   item_type;
       dbms_output.put_line ('Item_type: ' || l_item_type);
       dbms_output.put_line ('Count: ' || l_cnt);
    end;

  • Help with record selection/grouping

    I am trying to create a report as follows, but am running into some problems with my selection/grouping:
    Data Structure (each line is a separate record; each employee has 2 records)
    Employee             TaskID      TaskStatus           Marker         Date Modified
    1                               A                CLOSED             x
    1                               B                OPEN                  N/A
    2                               A                CLOSED              y
    2                               B                OPEN                 N/A
    3                               A                CLOSED             x
    3                               B                CLOSED            N/A
    4                               A                CLOSED             y
    4                               B                CLOSED           N/A
    Report Requirements
    I want a report that displays only employee number and the date that Task B was completed for all employees, and I want these records grouped based on Task B's Task Status (no problem.  I did this).
    However, I want to sub-group these Task B records (within Task Status) by the Marker field for Task A records!  (I can't figure this out?  If I only pull in Task B records, how can I compare what the associated employee has as a marker for their Task A record?)
    Again, I only want to display data from the employee's Task B record, while subgrouping on a field value from the empoyee's Task A record.  The report would be structured as follows:
    Task B (OPEN), with Task A - Marker (x)
                     {Date Modified}
    Task B (OPEN), with Task A - Marker (y)
                     {Date Modified}
    Task B (CLOSED), with Task A - Marker (x)
                    {Date Modified}
    Task B (CLOSED), with Task A - Marker (y)
                      {Date Modified}
    Thanks.
    Gary

    The easiest way would be to use an SQL Command that returns both the Task A and Task B data on one record.  Something like (MS SQL):
    select b.employee, b.taskid as task_b, b.task_status_b, b.marker as marker_b, b.date_modified as date_modified_b,
        a.taskid as task_a, a.task_status_a, a.marker as marker_a, a.date_modified as date_modified_a
    from table a, table b
    where a.employee = b.employee
    and a.taskid = 'A'
    and b.taskid = 'B'
    HTH,
    Carl

  • SQL to group by n days

    i would like know how i can perform grouping based on every n day interval.
    for example, i want to group the data based on an n=2day interval
    example table:
    DATE VALUE
    12/12/2005 2:52:00 PM 10
    12/12/2005 4:49:00 PM 20
    13/12/2005 5:17:00 AM 30
    13/12/2005 5:20:00 AM 40
    14/12/2005 9:36:00 AM 50
    14/12/2005 9:49:00 AM 60
    expected result:
    STARTDATE ENDDATE SUM(VALUE)
    12/12/2005 13/12/2005 100
    14/12/2005 15/12/2005 110
    but i also want to be able to change the value of n (in days)
    Thanks in advance.
    Simon

    something like...
    SQL> def n = 1
    SQL> select min(hiredate) start_date, min(hiredate)+&&n end_date, sum(sal) from emp
      2  group by hiredate, hiredate+&&n order by 1,2;
    old   1: select min(hiredate) start_date, min(hiredate)+&&n end_date, sum(sal) from emp
    new   1: select min(hiredate) start_date, min(hiredate)+1 end_date, sum(sal) from emp
    old   2: group by hiredate, hiredate+&&n order by 1,2
    new   2: group by hiredate, hiredate+1 order by 1,2
    START_DATE END_DATE     SUM(SAL)
    17/12/1980 18/12/1980        800
    20/02/1981 21/02/1981       1600
    22/02/1981 23/02/1981       1250
    02/04/1981 03/04/1981       2975
    01/05/1981 02/05/1981       2850
    09/06/1981 10/06/1981       2450
    08/09/1981 09/09/1981       1500
    28/09/1981 29/09/1981       1250
    17/11/1981 18/11/1981       5000
    03/12/1981 04/12/1981       3950
    23/01/1982 24/01/1982       1300
    START_DATE END_DATE     SUM(SAL)
    19/04/1987 20/04/1987       3000
    23/05/1987 24/05/1987       1100
    13 rows selected.where n is the 'day interval'

  • Help with sql subquery/grouping

    Hi... having trouble getting this query to work. Here's the table and data:
    create table mytable (
    rec_num number,
    status_num number,
    status_date date
    insert into mytable values (1,1,'01-AUG-2006');
    insert into mytable values (1,2,'14-AUG-2006');
    insert into mytable values (1,8,'01-SEP-2006');
    insert into mytable values (1,3,'15-SEP-2006');
    insert into mytable values (1,2,'03-SEP-2006');
    insert into mytable values (2,2,'17-AUG-2006');
    insert into mytable values (3,2,'02-SEP-2006');
    insert into mytable values (3,4,'07-SEP-2006');
    insert into mytable values (4,1,'18-SEP-2006');
    insert into mytable values (4,4,'27-SEP-2006');
    insert into mytable values (4,2,'18-SEP-2006');
    insert into mytable values (5,1,'01-OCT-2006');
    insert into mytable values (5,2,'03-OCT-2006');
    insert into mytable values (5,3,'05-OCT-2006');
    insert into mytable values (6,1,'01-OCT-2006');
    insert into mytable values (7,2,'14-OCT-2006');
    insert into mytable values (7,8,'15-OCT-2006');
    I'm trying to select the rec_num, status_num, and status_date for the max date for each individual rec_num... it basically tells me the current status of each individual record by getting the status for the most recent date... like the following:
    rec_num, status_num, date
    1, 3, 15-SEP-2006
    2, 2, 17-AUG-2006
    3, 4, 07-SEP-2006
    etc
    This query works... it gets me the max date for each record... but it doesn't give me the status_num:
    select rec_num, max(status_date)
    from mytable
    group by rec_num
    Adding status_num messes it up... I know I need some kindof sub-query, but haven't been able to get one to work.
    I'd also like a query to get a count on how many records currently exist in each status.
    Can someone help me out? Oracle 8i. Thanks!

    SQL> select * from my_table;
       REC_NUM STATUS_NUM STATUS_DA
             1          1 01-AUG-06
             1          2 14-AUG-06
             1          8 01-SEP-06
             1          3 15-SEP-06
             1          2 03-SEP-06
             2          2 17-AUG-06
             3          2 02-SEP-06
             3          4 07-SEP-06
             4          1 18-SEP-06
             4          4 27-SEP-06
             4          2 18-SEP-06
             5          1 01-OCT-06
             5          2 03-OCT-06
             5          3 05-OCT-06
             6          1 01-OCT-06
             7          2 14-OCT-06
             7          8 15-OCT-06
    SQL> select mt.rec_num,
      2         mt.status_num,
      3         mt.status_date
      4    from (select row_number() over (partition by rec_num order by status_date desc) rn,
      5                 rec_num,
      6                 status_num,
      7                 status_date
      8            from my_table) mt
      9   where mt.rn = 1;
       REC_NUM STATUS_NUM STATUS_DA
             1          3 15-SEP-06
             2          2 17-AUG-06
             3          4 07-SEP-06
             4          4 27-SEP-06
             5          3 05-OCT-06
             6          1 01-OCT-06
             7          8 15-OCT-06
    7 rows selected.
    SQL>

  • Select, grouping and counting...

    Hi again, I managed to bypass my trigger problem, so thanks a lot...!
    Now, I have a simple question...
    Using two tables, Joueur (NoJ (PK), NoE(PK, FK1), NomJ, Adresse, Tel, CoJ)
    and Equipe (NoE(PK,FK1), NomE, NoJC(Fk1 of NoJ))
    I'll explain the model...
    It's a Team table, and a Player Table.
    Naturally, the PK on Player (Joueur) is NoE (team number) and NoJ (Player number)
    On the Team table, the primary key is NoE (Team number
    and the foreign key is NoE AND NoJC which stands for the number of the CAPTAIN player ...
    So...
    I've got to make a table of 4 cloumns: Team number (NoE), Team name (NomE), Team captain name, number of player in team...
    So I need to combine those two tables... on the first table, I got all the info BUT the number of players, which lists all 1 due to the where NoJC = NoJ... but this function is required to get the Captain name...
    Select NoE, NomE, NomJ as Capitaine, count(*)
    from EQUIPE join JOUEUR using (NoE)
    where NoJ=NoJC
    group by NoE, NomE, NomJ;
    select noe, count(*)
    from EQUIPE join JOUEUR using (NoE)
    group by noe;Any clue?

    I suggest for you :
    Put then column noJC in joueur table nojc NUMBER CONSTRAINT fk_no_joueur_cap REFERENCES joueur(noj);
    Regards Salim.
    SQL> DROP TABLE joueur;
    Table supprimée.
    SQL> DROP TABLE equipe;
    Table supprimée.
    SQL> CREATE TABLE equipe (noe NUMBER CONSTRAINT pk_no_eq PRIMARY KEY, nome VARCHAR2(30));
    Table créée.
    SQL> CREATE TABLE joueur (noj NUMBER CONSTRAINT pk_no_joeur PRIMARY KEY,
      2                       noe NUMBER CONSTRAINT fk_no_equipe REFERENCES equipe(noe),
      3                       nomj VARCHAR2(30), adresse VARCHAR2(100), tel VARCHAR2(20),
      4                       coj VARCHAR2(10), nojc NUMBER CONSTRAINT fk_no_joueur_cap REFERENCES joueu
    r(noj) );
    Table créée.
    SQL> INSERT INTO equipe
      2       VALUES (1, 'RC Kouba');
    1 ligne créée.
    SQL> INSERT INTO joueur
      2       VALUES (1, 1, 'Salim', '... Montreal', '514-111-1111', 'NNN', NULL);
    1 ligne créée.
    SQL> INSERT INTO joueur
      2       VALUES (2, 1, 'Richard', '... Montreal', '514-111-2222', 'NNN', 1);
    1 ligne créée.
    SQL> INSERT INTO joueur
      2       VALUES (3, 1, 'Stéphane', '... Montreal', '514-111-3333', 'NNN', 1);
    1 ligne créée.
    SQL> COMMIT ;
    Validation effectuée.
    SQL>
    SQL> SELECT   equipe.noe, equipe.nome, j.noj nojc, j.nomj capitaine,
      2           COUNT (joueur.noj) AS "Nombre de joueurs"
      3      FROM joueur, equipe, joueur j
      4     WHERE joueur.noe = equipe.noe AND j.noe = equipe.noe AND j.nojc IS NULL
      5  GROUP BY equipe.noe, nome, j.noj, j.nomj;
           NOE NOME                                 NOJC CAPITAINE                      Nombre de joueurs
             1 RC Kouba                                1 Salim                                          3
    SQL>

  • Field Selection Group for Batch Management

    Hi All,
    I do not want to make the field mandatory for Raw Material during creation of material master.
    I checked the fileld selection group for MARA-XCHPF for ROH material type, MM01 , it is optional.
    But when i try to create the Material Master for ROH it is showing mandatory field.
    Amit Shah

    Hi,
    Go to the OMS9, here enter the Field sel. group 75 for your MARA-XCHPF, enter and then check the ROH Field refrece, if it shows required then select either Optinal entry or Hide or Display as per the requirement.
    Check and revert.
    Hrishi

  • Reg: SQL select Query in BPEL process flow

    <p>
    Hi,
    I am suppose to execute a SQL select query (in BPEL Process flow) as mention below in JDeveloper using Database adapter.
    </p>
    <p>
    SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
    </p>
    <p>
    LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
    </p>
    <p>
    FROM CUBE
    </p>
    <p>
    WHERE ITEM= &lt;xyz&gt;
    </p>
    <p>
    AND OBJECT= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=&lt;xyz&gt; AND SUPP_IND = &lsquo;Y')
    <strong>Now my question is:
    1.</strong> What does this "*" refer to in the query and how can I retrieve the value of LENGTH*WIDTH* HEIGHT from the query where LENGTH,WIDTH and HEIGHT are the individual field in the table.
    2.What does this " AS" refer to? If " ITEM_CUBE " is the alies for the table name "ITEM" to retrieve the value, then query shoud be evaluated as
    </p>
    <p>
    SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
    </p>
    <p>
    LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
    </p>
    <p>
    FROM CUBE
    </p>
    <p>
    WHERE <strong>ITEM_CUBE.ITEM</strong>= &lt;xyz&gt;
    </p>
    <p>
    AND <strong>ITEM_CUBE.OBJECT</strong>= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=&lt;xyz&gt; AND SUPP_IND = &lsquo;Y')
    Is my assumption correct?
    Please suggest asap.
    Thanks...
    </p>
    <p>
    </p>

    Hi
    Thank for your reply!
    I have a nested select query which performs on two different table as shown below:
    <p>
    SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
    </p>
    <p>
    LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
    </p>
    <p>
    FROM CUBE
    </p>
    <p>
    WHERE ITEM= &lt;abc&gt;
    </p>
    <p>
    AND OBJECT= (SELECT NAME FROM SUPPLIER WHERE ITEM=&lt;Item&gt; AND SUPP_IND = &lsquo;Y')
    I am using DB adapter of Oracle JDeveloper in BPEL process flow, where I can able to select only one master table in DB adapter say SUPPLIER and its attributes at a time.But as per my requirment I need to select both the table (CUBE and SUPPLIER) in a single adapter to execute my query.
    It can be achievable by using two DB adapter , One to execute the nested query and another to execute the main qyery considering value of nested query as a parameter.But I want to achieve it by using a single one.
    Am I correct with my concept?
    Please suggest how to get it ?
    </p>
    Edited by: user10259700 on Oct 23, 2008 12:17 AM

  • AppleScript to Select Groups of 3 Files?

    Hi all,
    Thanks in advance for any help you can provide. I am trying to create an AppleScript to take groups of 3 files and put them each in their own folder, inside of a master container folder. The files will typically be in DNG format as they will be from my digital camera—3 exposures of the same scene.
    Input example: folder containing files IMG_0022.dng, IMG_0023.dng, IMG_0024.dng, IMG_0025.dng, ... IMG_0052.jpg
    Output example:
    Container folder hdr_images
    folder images_group1
    IMG_0022.dng
    IMG_0023.dng
    IMG_0024.dng
    folder images_group2
    IMG_0025.dng
    IMG_0026.dng
    IMG_0027.dng
    folder images_group10
    IMG_0049.dng
    IMG_0050.dng
    IMG_0051.dng
    This is the script I have thus far, but I know there are errors and I can't get it to work the way I want:
    -- begin script
    tell application "Finder"
              -- Select all files in the folder selected from dialog box
                          set theFiles to files of folder (choose folder)
              -- Prepare to select groups of 3 files (1-3, 4-6, 7-9, etc.)
              set theInterval to 3
              -- Initialize the number of the group of 3 images
                          set groupNumber to 0
              -- Display dialog requesting location to create new folder
              set p to path to desktop
              -- Create new container folder in specified location
                          make new folder at p with properties {name:"seq_groups"}
              -- Loop through groups of 3 files, each time creating a container folder
              -- and copying the 3 files to that container folder
                          repeat with i from 1 to (count theFiles) by theInterval
                                            set groupNumber to groupNumber + 1
                                            set itemsToCopy to null
                                            set itemsToCopy to item i of theFiles
                                            set itemsToCopy to itemsToCopy & item i+1 of theFiles
                                            set itemsToCopy to itemsToCopy & item i+2 of theFiles
                                            copy files itemsToCopy to folder ____
              end repeat
              -- Display message box confirming success
    end tell
    You can see from the comments that I'd like to have it flow as follows:
    User either drags a folder onto the script, selects from the Services menu, or runs the applet to get a dialog box to choose folder
    Applet runs on all images within the folder and copies, rather than moves (just in case something goes terribly wrong)
    Applet confirms it is finished
    Any help would be greatly appreciated. Thanks again!

    Thanks, I played with it a bit more and this is the final result after more googling:
    tell application "Finder"
              set source_folder to (choose folder with prompt "Choose Source Folder")
              set container_folder to (choose folder with prompt "Choose Destination Folder")
              set the_count to 1
      sort files in folder source_folder by name
              repeat ((count files in folder source_folder)) div 3 times
      make folder at folder container_folder with properties {name:"images_group" & the_count}
                        set the dest_folder to folder ("images_group" & the_count) of container_folder as alias
      duplicate files ((the_count * 3) - 2) thru (the_count * 3) of folder source_folder to folder dest_folder
                        set the_count to the_count + 1
              end repeat
    end tell
    The only problem I continue to have is that it's not going by the "Finder order" of image sequence. Because each group of 3 is a different "scene" I need to make sure that wherever the file numbering sequence starts, it goes in order. Ideally, I'd like for it to read the metadata from the image files (they're all in DNG) and sort by capture time, but that seems a bit outside the scope of AppleScript's capabilities. Thank you again for your help!

Maybe you are looking for

  • Problem of POP LOV  in a  SQL Report  with pagination

    I am using a pop up lov (along with some other fields), HTMLDB_ITEM.POPUP_FROM_LOV(5, null, 'EMPLOYEE_LIST', '20', '50')), in a sql report. This is a report with pagination. Whenever I select any value from pop up lov on first page of the report it g

  • Trouble Printing Multiple Pages in Quick Succession - LaserJet P4015x - Networked Printer

    Hi, We are currently experiencing problems printing multiple pages in quick succession. We use a bespoke Microsoft Access Database to run our Sales Order Processing. As part of this software we print 3 part invoices, credit notes etc on different col

  • Value references

    Hello, although I've looked through the numbers handbook, I can't seem to find a solution to my syntax error: I'd like to give my illustration students project grades from 1 to 6 (German system) based on their percentages. I'd tried using the numbers

  • Add custom long text in MM01/02/03

    Hii ,  expert ? I need to add custom long text  in MM beside existing basic data text, inspection text, internal comment , purchasing text ,sales text , How to do it ? Thanks ads

  • Restoring the iTunes application completely

    I'm am kind of a new Macbook user, so please excuse my current stupidity, im not entirely tech-savvy. I was wondering if there is a way to completely restore the iTunes application because i stupidly downloaded the iLike sidebar for iTunes. I don't w