query SQL max function need help

Hi all

Its simple, but I'm not able to identify the problem.

In our HRMS EBS R12, 11g database we seeded table per_all_people_f and the column employee_number (varchar2).

case 1: normal employees whose employee_number starts with the numerical value. (for example: 9213,9214,9999,10000,10001)

case 2: employee_number starts with tank like 'P' - (for example: "P-1245', ' P-1246'" ")

I am writing as a small query to get the Max (employee_number) for case 1.

Select max (employee_number) in per_all_people_f

where employee_number not like 'P-% '.

Output: 9999 (didn't come out desired)

where I employee_number 10000 and 10001.

Select * from per_all_people_f where employee_number = "10000"

Returns the values of the table...

Please let me know why (employee_number) max is coming "9999"...

Thank you and best regards,

Afzal.

then try to do this:

Select employee_number

of per_all_people_f

where employee_number not like 'P-% '.

and translate(employee_number,'x0123456789','x') is not null;

to find out what other non-digital employee_numbers you next to the P - prefix ones.

HTH

Tags: Database

Similar Questions

  • Query SQL or function...

    Hi everyone,
    
    
      Please help me to clarify this question
    I have a "patient" table and a "address" table.And each patient has differnt types of addresses
    like PMI,Mailing and default address i need to pick patient address in the order of preference
    (PMI,Mailing ,Default)
    
    I have two options to get the address of a patient.Either write a SQL query to get the address of a 
    patient(according to preference)
    or write a function which checks
    
     if there is PMI,Mailing and default
      take PMI
     or
     If there is mailing and Default
     take mailing
     or
     take default.
    
    which one is the best method to get the address of a patient?  SQL query or function..
    Definitely everyone will say that it should be direct SQL query instead of multiple function calls.
    
    But in my organization there are many developers which will get "patient address" in their application 
    or SQL code or PL/SQL code or from some
    'X' Business intelligence tool.
    At this scenario is it best to have a function which every one will call and get a standardized output
     for every one.
    
    Question:
    
    In my scenario which one is the best to have "SQL query or function"?
    if i choose "function" i have to sacrifice the performance 
    if i choose "SQL query" i am not sure whether each and every developer querying the same way as it would be
    
    
    Sorry if it is a dumb question to ask.
    
    Thanks in advance
    phani

    hoek question: what happens if I have to choose between the SQL and function? (Assume that they do not accept to create views)

    If views are not accepted (which is very strange IMO), but you need some "standard object" which anyone can use, then you would choose to use a function instead of everyone having "their own motion.
    It is a compromise between maintaining standards and performance (call PL/SQL in SQL is generally to be avoided because of context switching, the other way around is OK).
    One of the advantages of a view: no problems with the settings you must enter but never going to use, you just choose the columns you need and there you go.
    Other: it is simple, plain and simple.
    It is easier to maintain.
    But everything depends on what your function returns.
    Maybe a REF CURSOR?

    Your question reminds me of this interesting discussion:

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:672724700346558185

    Published by: hoek on July 1st, 2009 16:39 tyop

  • On query performance problem. Need help.

    It is essentially a performance problem. I hope someone can help me with that.

    Basically, I have four old masters (150000 records), (100000 records) Child1, Child2 (50 million records!), child 3 (10000 + records)
    (please forgive the alias).

    Each record in the master has now more than one matching record in each table child (one to many).
    Also there may be any record in any or all of the tables for a particular master record.

    Now, I need to get the maximum of last_updated_date for each master record in each table 3 child and then find the maximum of
    the three obtained last_active_dates from the 3 tables.
    for example: Master ID 100, to interrogate Child1 for all Master ID 100 records and get the max last_updated_date.
    Same for the other 2 tables and get the most out of these three values.
    (I also need to deal with cases where no trace may be found in a child table to a Master ID)

    Write a procedure that uses sliders that the value of each of the performance hits of child table
    evil. And that's, I need to know the last_updated_date for each master file (all 150000 of them). It will probably take days to do this.

    SELECT MAX (C1. LAST_UPDATED_DATE)
    MAX (C2. LAST_UPDATED_DATE)
    MAX (C3. LAST_UPDATED_DATE)
    OF CHILD1 C1
    CHILD2 C2
    CHILD3 C3
    WHERE C1. MASTER_ID = 100
    OR C2. MASTER_ID = 100
    OR C3. MASTER_ID = 100

    I tried the above, but I got an error in tablespace temp. I don't think that the application is good enough at all.
    (The GOLD clause is to take care of any records in a child table. If there is an AND, then the join and then select
    No, not even if there is no record in a child table, but valid values in the other 2 tables).

    Thank you very much.

    Published by: user773489 on December 16, 2008 11:49

    You want alias to this field then.

    SELECT MAX (C.LAST_UPDATED_DATE)
    FROM
    (select child1_master_id MASTER_ID, field2, field3,... field4 from CHILD1 UNION ALL
     select child2_master_id MASTER_ID, field2, field3,... field4 from CHILD2 UNION ALL
     select child3_master_id MASTER_ID, field2, field3,... field4 from CHILD3) C
    WHERE C.MASTER_ID = 100
    

    If do you something like that, and explicitly list the columns you want.

    Edit: for something like a specific query for a MASTER_ID...

    SELECT MAX (C.LAST_UPDATED_DATE)
    FROM
    (select child1_master_id MASTER_ID, LAST_UPDATED_DATE from CHILD1 where child1_master_id = 100 UNION ALL
     select child2_master_id MASTER_ID, LAST_UPDATED_DATE from CHILD2 where child2_master_id = 100 UNION ALL
     select child3_master_id MASTER_ID, LAST_UPDATED_DATE from CHILD3 where child3_master_id = 100) C
    WHERE C.MASTER_ID = 100
    

    That should give you very good performance by raising a record. But a better idea, as indicated, would be to get it all at once with a sql:

    SELECT MASTER_ID, MAX(C.LAST_UPDATED_DATE)
    FROM
    (select child1_master_id MASTER_ID, LAST_UPDATED_DATE from CHILD1 UNION ALL
     select child2_master_id MASTER_ID, LAST_UPDATED_DATE from CHILD2 UNION ALL
     select child3_master_id MASTER_ID, LAST_UPDATED_DATE from CHILD3 ) C
    GROUP BY MASTER_ID
    

    This will give you the max for each MASTER_ID in a sql without a cursor.

    Published by: tk-7381344, December 16, 2008 12:12

  • Introduction to programming in SQL, einreihig functions, please help

    Hello

    I'm taking my first class of SQL programming, and I have no experience with SQL. Some of the exercise questions give me wrong, so I was hoping that someone would be kind enough to help.

    I'm supposed to write a query that displays the name of the family (with the first letter capitalized and all other letters lowercase) and the length of the name of everyone whose name begins with the letters J, or M.


    The second part, where I include employees whose name begins with J, A, or M, gives me fits. I can query an initial one at a time, but I was not able to interview several initials.

    That's what I have so far:

    SELECT INITCAP (last_name), 'Name', LENGTH (last_name) "length".

    Employees

    WHERE last_name LIKE'm %';

    But, when I try to ask for M, and J I get errors.

    For example:

    SELECT...

    Of...

    WHERE last_name LIKE am %A %%J ';

    I have tried so many combinations, it's driving me crazy.

    Help, please?

    Thank you very much!

    Please be kind, this is my first post.

    Hello

    Welcome to the forum!

    In the WHERE clause, you can have a State composed, i.e. 2 or more simple conditions combined by using GOLD or et.  In this case:

    WHERE last_name LIKE'm %'

    OR last_name LIKE 'a % '.

    OR last_name LIKE 'J % '.

    The WHERE clause as a whole is regarded as TRUE 1 if all the pieces of GOLD-bounded is TRUE,

    It's just one of the many ways to get the desired results.  The that I would probably use for this task is

    WHERE SUBSTR (last_name, 1, 1) IN (', 'A', 'J')

  • Simple sql statement I need help

    Hello all, I need the syntax for the following sql query: "Using that a single update to write the query to update a salary of 10% for wages below 100 k and 15% for salaries above 100 k". TIA

    UPDATE table1 SET salary = salary BOX WHEN < 100000="" then="" salary="" *="" 1.1="" when="" salary=""> = 100000 THEN salary * 1.15 END;

  • When no rows returned in the query loop, replace Null - need help

    Hello

    I have a requirement where I have a request in the loop for and based on the results of the query, I do some operations.

    But even if the query does not match, I should get back something like 'No Data'.

    My loop is:

    FOR V_SL IN)
    SELECT ID, CATEGORY, DI_CD, REV_CD, SL_ID
    OF SB, SLOT_2001 S2 SLOT_DATA WHERE
    PBM BENEFIT_ID = S2. BENEFIT_ID AND
    REV_CD = IN_REV_CD AND
    (PROC_CD IS NULL OR PROC_CD = IN_PROC_CD)
    ORDER OF DIAGCODE, PROCEDURECODE)
    LOOP
    END LOOP;

    I do some operations inside the loop for. I want the loop to run even if the query returns no rows.

    Can someone help me out here.

    Thank you
    Rambeau

    Frank. I am really surprised to see this coming from you. A slider to not find all the lines loop does not cause an exception no_data_found.

  • Query MDX... need help

    Hi Expert...
    I wrote a MDX query as follows:
    change the alias set session dml_output
    coil stdout to "C:\ACCT_110711.TXT."
    SELECT AXIS (0) {, {[year]. Members} ON AXIS (1) [CUBE];
    spool off;
    This generates a txt file with all output - including the query, I put and the message "the statement executed successfully.
    What should I do to get only results in a file. What is possible in Essbas... or do I have to manipulate the file using unix or something after the generation.

    The output of the queue to a file using Maxl is not the best, the MDX is not really the equivalent of report scripts.
    You could look at the analysis of the file after it is created, or maybe look at perl scripts or API or ODI or report to generate in a cleaner format.

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • Need help with a SQL query

    Hello

    I have a data in table (raj_table) with columns (char11) raj_id, raj_number (varchar2 (15)), raj_format (NUMBER), Primary_ID (identity with the values of the primary key column)

    Primary_ID raj_id Raj_number Raj_format

    1                            raj                 rajvend                      1

    2                            raj                 rajvend                      1

    3                            raj                 rajvendor1                 2

    4                            raj                 rajvendor1                 2

    5                            raj                 rajvendor1                 2

    6                            raj                 rajvendor2                 3

    I used under SQL to get query output as below, but has not achieved the required result:

    Select client_id vendor_number, vendor_format, primary_id, row_number() on sl_no (client_id partition, primary_id, vendor_format order of client_id primary_id, vendor_format, vendor_number, vendor_number)

    from raj_table by sl_no asc

    SL_NO raj_id raj_number raj_format primary_id

    1                   1                   raj              rajvendor                 1

    1                   2                  raj              rajvendor                 1

    2                   3                   raj              rajvendor1                2

    2                   4                   raj              rajvendor1                2

    2                   5                  raj               rajvendor1                2

    3                   6                    raj              rajvendor2                3

    I need help with a SQL query to get the result as above without using the group by clause. I want to bring together the combination of separate line of the three columns (raj_id, raj_number, raj_format) and add a unique serial number for each online game (SL_NO column below). So, above there are 3 unique set of (raj_id, raj_number, raj_format) I can get in a group by clause, but I can not add prmiary_id, SL_NO values if I group by clause. I used the analytical functions like row_number() but no luck. Need solution for this.

    with t as)

    Select 'raj' raj_id, 'rajvend' raj_number, 1 raj_format, 1 primary_id Union double all the

    Select option 2, 'raj', 'rajvend', 1 double Union all

    Select 3, 'raj', 'rajvendor1', 2 double Union all

    Select 4, 'raj', 'rajvendor1', 2 double Union all

    Select 5, 'raj', 'rajvendor1', 2 double Union all

    Select 6, 'raj', 'rajvendor2', 3 double

    )

    Select dense_rank() over (order of raj_id, raj_number, raj_format) sl_no,

    t.*

    t

    order by primary_id

    /

    PRIMARY_ID RAJ RAJ_NUMBER RAJ_FORMAT SL_NO
    ---------- ---------- --- ---------- ----------
    1 1 raj rajvend 1
    1 2 raj rajvend 1
    2 3 raj rajvendor1 2
    2 4 raj rajvendor1 2
    2 5 raj rajvendor1 2
    3 6 raj rajvendor2 3

    6 selected lines.

    SQL >

    SY.

  • Need help with PL/SQL query complex

    I need help with a query that need access to data from 3 tables. That's what I did

    I created 3 tables

    CREATE TABLE post_table
    (
    post_id varchar (20),
    datepost DATE,
    KEY (post_id) elementary SCHOOL
    ) ;

    CREATE TABLE topic
    (
    TOPIC_ID varchar (20),
    name varchar (20),
    PRIMARY KEY (topic_id)
    );

    CREATE TABLE blogpost_table
    (
    TOPIC_ID varchar (20),
    post_id varchar (20),
    PRIMARY KEY (topic_id, post_id);
    FOREIGN KEY (topic_id) REFERENCES topic (topic_id) ON DELETE CASCADE,
    FOREIGN KEY (post_id) REFERENCES post_table (post_id) ON DELETE CASCADE
    );


    Now, I inserted a few values in these tables as

    INSERT INTO post_table VALUES ('p1', to_date ('2009-09-14 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p2', to_date ('2009-07-18 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p3', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p4', to_date ('2009-03-11 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p5', to_date ('2009-07-13 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p6', to_date ('2009-06-12 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p7', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))

    INSERT INTO VALUES subject ("t1", "baseball");
    INSERT INTO category VALUES ('t2', 'football');

    INSERT INTO blogpost_table VALUES ("t1", "p1");
    INSERT INTO blogpost_table VALUES ('t1', 'p3');
    INSERT INTO blogpost_table VALUES ("t1", "p4");
    INSERT INTO blogpost_table VALUES ('t1', 'p5');
    INSERT INTO blogpost_table VALUES ('t2', 'p2');
    INSERT INTO blogpost_table VALUES ('t2', 'p6');
    INSERT INTO blogpost_table VALUES ("t2", "p7");


    I'm launching SQL queries on the table in this topic.

    I want to write a SQL query that returns me the name of a topic (s) and the number of blog_post (s) associated with the topic in descending order of the number of blog posts created in July.

    Can someone please help me to write this query?

    Thank you

    Published by: user11994430 on October 9, 2009 07:24

    Thanks for the test of the configuration!

    SQL>SELECT   t.NAME, COUNT(*)
      2      FROM topic t, blogpost_table b, post_table p
      3     WHERE b.topic_id = t.topic_id
      4       AND p.post_id = b.post_id
      5       AND p.datepost >= DATE '2009-07-01'
      6       AND p.datepost < DATE '2009-08-01'
      7  GROUP BY t.NAME
      8  ORDER BY COUNT(*) desc;
    
    NAME                   COUNT(*)
    -------------------- ----------
    baseball                      2
    soccer                        2
    

    HTH, Urs

  • Need help with query SQL Inline views + Group

    Hello gurus,

    I would really appreciate your time and effort on this application. I have the following data set.

    Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
    1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 20.00 *---19
    1234567 11223 - 05/07/2008 - 44345563 -a--10,00---19 ofbad quality adjustment
    7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
    4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19

    Please ignore '-' added for clarity

    I'm writing a paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, aggregate query Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Type, Invoice_Number, Vendor_Number. When there are no more records I want to display the respective Description.

    The query should return the following data set

    Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
    1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 10.00 *---19
    7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
    4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19
    Here's my query. I'm a little lost.

    Select b., A.sequence_id, A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    de)
    Select sequence_id, check_number, check_date, invoice_number, sum (paid_amount) sum, vendor_number
    of the INVOICE
    Sequence_id group check_date, check_number, invoice_number, vendor_number
    ) A, B OF INVOICE
    where A.sequence_id = B.sequence_id


    Thank you
    Nick

    It seems that this is a duplicate thread - correct me if I am wrong in this case->

    Need help with query SQL Inline views + Group

    Kind regards.

    LOULOU.

  • Need help to resolve the query by using analytic functions

    Hello

    I need help to solve this problem, I tried an analytical function but could not solve the problem.

    I have three table as illustrated below the table is filled with a flat file. The records are arranged sequentailly based on the name of the file.

    The first record of the game based on EIN goes to TAB_RCE
    the following records then goes to TAB_RCW
    and last save of the game based on EIN goes to the RCT table

    How can I make groups and
    assign a

    EIN * 12345 * line number * 02, 03, 04 * in the table TAB_RCW and * 05 * in the table TAB_RCT
    EIN * 67890 * line number * 07, 08, 09,10 * in the table TAB_RCW and * 11 * in the table TAB_RCT
    and so on...

    Thank you

    Rajesh

    TAB RCE_--------------------------------------------------------------
    LineNumber EIN FILENAME TYPE

    -----

    01 12345 ABC NCE. TXT
    06 67890 ABC NCE. TXT
    12 76777 ABC NCE. TXT

    -----
    TAB_RCW
    -----
    LineNumber TYPE SSN FILENAME
    -----
    02 22222 ABC RCW. TXT
    03 33333 ABC RCW. TXT
    04 44444 ABC RCW. TXT
    07 55555 ABC RCW. TXT
    08 66666 ABC RCW. TXT
    09 77777 ABC RCW. TXT
    10 88888 ABC RCW. TXT
    13 99998 ABC RCW. TXT
    14 99999 ABC RCW. TXT

    -----
    TAB_RCT
    -----
    NAME OF THE FILE OF TYPE LINENUMBER
    -----
    RCT 05 ABC. TXT
    RCT 11 ABC. TXT
    RCT 15 ABC. TXT
    -----
    SQL> with TAB_RCE as (
      2                   select 'RCE' rtype,'01' linenumber, '12345' EIN,'ABC.TXT' FILENAME from dual union all
      3                   select 'RCE','06','67890','ABC.TXT' from dual union all
      4                   select 'RCE','12','76777','ABC.TXT' from dual
      5                  ),
      6       TAB_RCW as (
      7                   select 'RCW' rtype,'02' linenumber,'22222' ssn,'ABC.TXT' FILENAME from dual union all
      8                   select 'RCW','03','33333','ABC.TXT' from dual union all
      9                   select 'RCW','04','44444','ABC.TXT' from dual union all
     10                   select 'RCW','07','55555','ABC.TXT' from dual union all
     11                   select 'RCW','08','66666','ABC.TXT' from dual union all
     12                   select 'RCW','09','77777','ABC.TXT' from dual union all
     13                   select 'RCW','10','88888','ABC.TXT' from dual union all
     14                   select 'RCW','13','99998','ABC.TXT' from dual union all
     15                   select 'RCW','14','99999','ABC.TXT' from dual
     16                  ),
     17       TAB_RCT as (
     18                   select 'RCT' rtype,'05' linenumber,'ABC.TXT' FILENAME from dual union all
     19                   select 'RCT','11','ABC.TXT' from dual union all
     20                   select 'RCT','15','ABC.TXT' from dual
     21                  )
     22  select  rtype,
     23          last_value(ein ignore nulls) over(partition by filename order by linenumber) ein,
     24          linenumber,
     25          ssn
     26    from  (
     27            select  rtype,
     28                    linenumber,
     29                    ein,
     30                    to_char(null) ssn,
     31                    filename
     32              from  TAB_RCE
     33            union all
     34            select  rtype,
     35                    linenumber,
     36                    to_char(null) ein,
     37                    ssn,
     38                    filename
     39              from  TAB_RCW
     40            union all
     41            select  rtype,
     42                    linenumber,
     43                    to_char(null) ein,
     44                    to_char(null) ssn,
     45                    filename
     46              from  TAB_RCt
     47          )
     48    order by linenumber
     49  /
    
    RTY EIN   LI SSN
    --- ----- -- -----
    RCE 12345 01
    RCW 12345 02 22222
    RCW 12345 03 33333
    RCW 12345 04 44444
    RCT 12345 05
    RCE 67890 06
    RCW 67890 07 55555
    RCW 67890 08 66666
    RCW 67890 09 77777
    RCW 67890 10 88888
    RCT 67890 11
    
    RTY EIN   LI SSN
    --- ----- -- -----
    RCE 76777 12
    RCW 76777 13 99998
    RCW 76777 14 99999
    RCT 76777 15
    
    15 rows selected.
    
    SQL> 
    

    SY.

  • Need help to form a query SQL/PLSQL

    Hello
    I'm not an expert in Oracle SQL. I need to have this query to improve the performance of my product. I have a table T that has a collar of column that is of type varchar. The neck is unique in the table (no two rows have the same value for the collar). Given a set S1 with 100 channels, the query should return me all channels in S1 who are not present in the neck.
    SQL query or PLSQL would be perfect. The query can have strings (elements of S1) hardcoded into it.

    Thanks in advance,
    Madhu

    user13290641 wrote:
    They are separate strings. They will be most likely hard-coded.

    In this case to pass them on in the form of record set as shown below, so that you can use operator LESS to get your result.

    with static_result_set as
    (
    select  'aaa' col from dual
    UNION ALL
    select  'xxx' from dual
    UNION ALL
    select  'ccc' from dual
    UNION ALL
    select  'zzz' from dual
    )
    select col from static_result_set
    minus
    select col from t
    
  • Need help with a query of type "connect by level.

    Hello, I recently met 'connect by level' and I think he can solve my problem, but maybe not. I would like to create rows of data where the number of rows created varies according to the data from the original table.

    It works:

    with times like

    (select to_date (' 26/01/2014 01:00 ',' dd/mm/yyyy hh24:mi:ss') starttime,)

    TO_DATE (' 27/01/2014 00:00:00 ',' dd/mm/yyyy hh24:mi:ss') stoptime

    the double)

    Select starttime, stoptime, starttime + rownum / 24

    of the time

    connect by level < =.

    (Select trunc ((stoptime-starttime) * 24: 2) at the time)

    I would like to do something similar for several lines (following does not work)

    with times like

    (select to_date (' 26/01/2014 01:00 ',' dd/mm/yyyy hh24:mi:ss') starttime,)

    TO_DATE (' 27/01/2014 00:00:00 ',' dd/mm/yyyy hh24:mi:ss') stoptime

    of the double

    Union

    Select to_date (' 25/01/2014 18:00 ',' dd/mm/yyyy hh24:mi:ss') starttime.

    TO_DATE (' 27/01/2014 00:00:00 ',' dd/mm/yyyy hh24:mi:ss') stoptime

    the double)

    Select starttime, stoptime, starttime + rownum / 24

    of the time

    connect by level < =.

    (Select trunc ((stoptime-starttime) * 24: 2) at the time)

    I need to stay away from solutions of PL/SQL, this query will be wrapped in an application that can not handle the PL/SQL, going and coming from the database (I also suck in PL/SQL).

    Any help would be greatly appreciated, I have no knowledge here, I tried to read some of the documentation on hierarchical queries, but it is not yet clicking.

    Thank you!

    Or also:

    SQL > WITH times

    2 ALSO (SELECT TO_DATE (' 01:00 26/01/2014 ', "hh24:mi:ss dd/mm/yyyy") Starttime)

    3, TO_DATE (' 01/26/2014 03:00 ', 'hh24:mi:ss dd/mm/yyyy') Stoptime

    4 FROM TWO

    5 UNION

    6 SELECT TO_DATE (' 25/01/2014 18:00 ', "hh24:mi:ss mm/dd/yyyy") Starttime

    7, TO_DATE (' 25/01/2014 22:00 ', 'hh24:mi:ss dd/mm/yyyy') Stoptime

    8 DOUBLE)

    9. SELECT T.*, Starttime + Lvl / 24

    10. OF time T

    11, (SELECT LEVEL Lvl

    THE DOUBLE 12

    13 CONNECT BY LEVEL<>

    14 (SELECT MAX (TRUNC ((Stoptime-Starttime) * 24)))

    15 AT the time)):

    16. WHERE the lvl<= trunc="" (="" (stoptime="" -="" starttime)="" *="">

    17 ORDER 1, 3

    18.

    STARTTIME STOPTIME-STARTTIME + LVL/24

    ----------------------------- ----------------------------- -----------------------------

    January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 19:00

    January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 20:00

    January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 21:00

    January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 22:00

    26 January 2014 01:00 26 January 2014 03:00 January 26, 2014 02:00

    26 January 2014 01:00 26 January 2014 03:00 January 26, 2014 03:00

    6 selected lines.

  • Need help with Oracle SQL merge records according to date and term dates

    Hi all

    I need help to find this little challenge.

    I have groups and flags and effective dashboards and dates of term against these indicators according to the following example:

    GroupName Flag_A Flag_B Eff_date Term_date
    Group_ATHERETHERE2011010199991231
    Group_ANN2010010120101231
    Group_ANN2009010120091231
    Group_ANN2006010120081231
    Group_ANTHERE2004010120051231
    Group_ATHERETHERE2003010120031231
    Group_BNTHERE2004010199991231
    Group_BNTHERE2003010120031231

    As you can see, group_A had the same combination of (N, N) flag for three successive periods. I want to merge all the time periods with the same indicators in one. Where entry into force will be the most early (underlined) time period and end date will be later (underlined)

    So the final result should look like this:

    GroupName Flag_A Flag_B Eff_date Term_date
    Group_ATHERETHERE2011010199991231
    Group_ANN2006010120101231
    Group_ANTHERE2004010120051231
    Group_ATHERETHERE2003010120031231
    Group_BNTHERE2003010199991231

    Thanks for your help

    Here's the DDL script

    drop table TMP_group_test;

    create table TMP_group_test (groupname varchar2 (8))

    , flag_a varchar2 (1)

    , flag_b varchar2 (1)

    , eff_date varchar2 (8)

    , term_date varchar2 (8)

    );

    insert into TMP_group_test values ('Group_A', 'Y', 'Y', ' 20110101 ', ' 99991231');

    insert into TMP_group_test values ('Group_A', 'n', ' n ', ' 20100101 ', ' 20101231');

    insert into TMP_group_test values ('Group_A', 'n', ' n ', ' 20090101 ', ' 20091231');

    insert into TMP_group_test values ('Group_A', 'n', ' n ', ' 20060101 ', ' 20081231');

    insert into TMP_group_test values ('Group_A', 'n', 'Y', ' 20040101 ', ' 20051231');

    insert into TMP_group_test values ('Group_A', 'Y', 'Y', ' 20030101 ', ' 20031231');

    insert into TMP_group_test values ('Group_B', 'n', 'Y', ' 20040101 ', ' 99991231');

    insert into TMP_group_test values ('Group_B', 'n', 'Y', ' 20030101 ', ' 20031231');

    commit;

    Post edited by: user13040446

    It is the closest, I went to the solution


    I create two rows;

    Rnk1: partition by group name, order of eff_date / / desc: this grade will sort the records of the most recent and handed to zero for each group\

    Rnk2: (dense) partition by group name, flag_A, flagb: this grade for each combination of group\flag gives a number so that they are classified as "families".

    Then I use the function analytic min

    Min (eff_date) more (partition of GroupName, rnk2): the idea is that, for each Member of the same family, the new date is the min of the family (and the max for the date of the term), at the end I just need separate so that the duplicates are gone

    Now the problem. As you can see from the query below, records of 1 and 6 (as identified by rownum) are identified in the same family, because they have the same combination of flag, but they are not successive, so everyone must keep its own date of entry into force.

    If only I can make the distinction between these two that would solve my problem


    Query:


    Select rowNum,GroupName, flag_a, flag_b, eff_date, term_date, rnk1, rnk2

    , min (eff_date) more than (partition by GroupName rnk2( ) min_eff

    Of

    (

    Select rowNum,

    GroupName , flag_a , flag_b , eff_date , term_date

    rank() more than (partition by GroupName stopped by eff_date desc) rnk1

    DENSE_RANK() more than (partition by GroupName order by flag_A flag_B ( ) rnk2

    de dsreports . tmp_group_test

    ) order by rowNum

    Hello

    user13040446 wrote:

    Hi KSI.

    Thanks for your comments, you were able to distinguish between these lines highlight, but lost lines 2,3,4 which are supposed to have the same date min = 20060101.

    Please see the table wanted to see the final result I want to reach

    Thanks again

    This first answer is basically correct, but in the main query, you want to use the function MIN, not the analytical function aggregation and GROUP BY columns with common values, like this:

    WITH got_output_group AS

    (

    SELECT GroupName, flag_a, flag_b, eff_date, term_date

    ROW_NUMBER () OVER (PARTITION BY GroupName

    ORDER BY eff_date

    )

    -ROW_NUMBER () OVER (PARTITION BY GroupName, flag_a, flag_b)

    ORDER BY eff_date

    ) AS output_group

    OF tmp_group_test

    )

    SELECT GroupName, flag_a, flag_b

    MIN (eff_date) AS eff_date

    MAX (term_date) AS term_date

    OF got_output_group

    GROUP BY GroupName, flag_a, flag_b

    output_group

    ORDER BY GroupName

    eff_date DESC

    ;

    The result I get is

    GROUP_NA F F EFF_DATE TERM_DAT

    -------- - - -------- --------

    Group_A Y 20110101 99991231 Y

    N Group_A 20101231 20060101 N

    Group_A N 20051231 20040101 Y

    Group_A Y Y 20031231-20030101

    Group_B N Y 99991231 20030101

    which is what you asked for.

  • need help for this query

    Hi gurus

    need help with this query,

    I want to display the records in the table emp
    SQL> Select Deptno,sal,sal/SUMSAL Percent,rn
      2  From  ( Select emp.*,Sum(Sal) Over() "SUMSAL",Row_number() Over(Order by sal Desc) rn
      3   From emp
      4        )
      5  /
    
          EMPNO     DEPTNO        SAL    PERCENT         RN
    --------- ---------- ---------- ---------- ----------
         7839         10       5000 .172265289          1
         7902         20       3000 .103359173          2
         7788         20       3000 .103359173          3
         7566         20       2975 .102497847          4
         7698         30       2850 .098191214          5
         7782         10       2450 .084409991          6
         7499         30       1600 .055124892          7
         7844         30       1500 .051679587          8
         7934         10       1300 .044788975          9
         7521         30       1250 .043066322         10
         7654         30       1250 .043066322         11
         7876         20       1100 .037898363         12
         7900         30        950 .032730405         13
         7369         20        800 .027562446         14
    
    14 rows selected.
                   
     
    I want just the records
          EMPNO     DEPTNO        SAL    PERCENT         RN
    ---------- ---------- ---------- ---------- ----------
          7839         10       5000 .172265289          1
          7902         20       3000 .103359173          2
          7788         20       3000 .103359173          3
          7566         20       2975 .102497847          4
          7698         30       2850 .098191214          5
    with sum (Percent) of remaing records.....
        Others                          .420327304  
    Thank you

    Published by: SeenuGuddu on February 27, 2011 03:39
    with a as
    (
    Select
    Empno, Deptno ,sal, sal/SUMSAL Percent,
    case when rn<=5 then rn else null end rnm
    From  (Select emp.*, Sum(Sal) Over() "SUMSAL",
    Row_number() Over(Order by sal Desc) rn
    From emp)
    )
    select
    case when max(rnm) is not null then to_char(max(empno)) else 'Others:' end empno,
    case when max(rnm) is not null then max(deptno) else null end deptno,
    case when max(rnm) is not null then max(sal) else null end sal,
    to_char(sum(percent), '90.99') percent,
    max(rnm) rn
    from a
    group by rnm order by rnm
    
    EMPNO                                    DEPTNO                 SAL                    PERCENT RN
    ---------------------------------------- ---------------------- ---------------------- ------- ----------------------
    7839                                     10                     5000                     0.17  1
    7902                                     20                     3000                     0.10  2
    7788                                     20                     3000                     0.10  3
    7566                                     20                     2975                     0.10  4
    7698                                     30                     2850                     0.10  5
    Others:                                                                                  0.42                         
    
    6 rows selected
    

Maybe you are looking for

  • How to connect the table 1 d to Structure box as a selector of case

    Hi all I'm able analog DAQmx Coordinated, I got component (Y) waveform and this component is of data type table 1 d (double-64-bit real) wire, according to my program I have to use the structure of the case, the selector must be values Y but labview

  • cRIO input voltage level

    I use a cRIO 9004. I noticed it has a chassis temp option. I was wondering if there was a way to find the input voltage. My unit is battery powered and I knew my batery voltage level. I'm doing some kind of a voltage drop detector. I am a novice to L

  • Upgrading an Envy 15-j171nr with 8GB and 24GB SSD 16 GB cache

    I'm a 15-j171nr with 8GB and 24 GB SSD cache. Whe I have it set to purchase the Configurator said the cache of 24GO was incompatible with more than 8 GB of RAM.  'Maintenance and Service of Guide' (p/n 733845-001) said the same thing on page 5: «mSAT

  • H50113 modem fax, caller ID not working not

    Original title: H50113 data fax modem upgrade modem installed through windows update, modem now caller ID does not work

  • Windows 7 will not identify Nikon d5000.

    Original title: windows 7 and nikon d5000. Windows 7 does not recognize the nikon d5000 as a device connected via usb - suggestions?