Need help to write a better SQL query

Hi gurus,

Please let me know your best query for the problem below:

Suppose we have 2 tables in Oracle 10 G database:

IM1: product and warranty sales records

A: sales_id

B: product QTY.

C: quantity of product

D: Service QTY.

E: Service amount

IM1 table:

a b c d and e

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

1 1 100 1 10

2 1 150 1 70

3 2 500 1 100

4 1 100 0 0

IM2: brand and product guarantee service term associated with record sales

A: sales_id

G: the Service life

P: brand product of

Z: flag of product/Service

IM2 table:

a    g               p          z

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

1 sony NULL p

1 monthly NULL g

Dell 2 p, NULL reference

Reg 2 g NULL

NULL lenovo 3 p

3 monthly NULL g

Sony NULL 4 p

Then, he must bring the "term of Service" and "Brand product" in line with the sales table, as below:

ID h_qty h_amnt g_qty g_amnt brand term

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

1 1 100 1 10 sony monthly

2 1 150 1 70 dell Reg

3 2 500 1 100 lenovo monthly

4 1 100 0 0 sony NULL

What I wrote myself is as below, but I want to know if there is a better idea to make the query more reliable, because real paintings are big and my query is slow.

SELECT DISTINCT

ID of the s.a,

s.b h_qyt,

s.c. h_amnt,

Virginia g_qty,

Sager g_amnt

brand of the PDP,

term of r.g

Of

(SELECT s.*, PDP FROM s im1, im2 p WHERE s.a = p.a. PDP AND IS NOT NULL).

IM2 p,

IM2 g

WHERE s.a. = p.a.

AND s.a. = g.a

AND (p.z = 'p' AND WINS = 'g')

OR (p.z = 'p' AND WINS = 'p' AND sagehomme = 0 AND s.p = pp)

ORDER BY 1;

Here you will find the table scripts:

create table im1 (a number, b, c number, number d, e number);
create table im2 (a number g char (10), char (10) p, z (1) tank);
insert into values im1 (1,1,100,1,10);
insert into values im1 (2,1,150,1,70);
insert into values im1 (3,2,500,1,100);
insert into values im1 (4,1,100,0,0);

Insert in im2 values (1, null, 'sony', 'p');
Insert in im2 values (1, 'Monthly', null, 'g');
Insert in im2 values (2, null, 'dell', 'p');
Insert in im2 values (2, 'Reg', null, 'g');
Insert in im2 values (3, null, 'lenovo', 'p');
Insert in im2 values (3, 'Monthly', null, 'g');
Insert in im2 values (4, null, 'sony', 'p');

something like below

Select x.a as id, x.b as h_qty, x.c as h_amnt, Eliane as g_qty, x.e as g_amnt, min (y.p) as min (y.g) as mark

-min (y.p) compared to (x.a partition) as min (y.g) on (x.a partition) as the term mark
of im1, im2 XY
where x.a = y.a
Group of x.a, x.b, x.c, Eliane x.e

Edited: putting aggregation function instead of the function min min Analytics

Tags: Database

Similar Questions

  • Need help to write original Victorian SQL of a tricky requirement statement

    Hello

    I have a table with the following structure

    ID Number (10)
    Company Varchar2 (100)
    Products Varchar2 (4000)

    The area of the stored products the list separated by commas in the names of products, which the company deals in.

    I want to know the number of companies for each product and organize the product list in descending order of their number

    For example, the sample data as follows

    The company produced ID
    1 a readers of portable barcode of desktop computers, the readers of barcodes, computer laptop, system memory,
    2B Handcrafted Wallets leather, holders of credit card in leather, handbag leather, ladies handbag, Designer handbag
    C 3 laptops, desktops
    4 d, leather wallet, handbag ladies
    5 E ladies handbag, ladies, ladies Sandals boots
    6 F designer handbag, handbag ladies

    Now, here's the result I want

    Nr. of companies article
    Handbag ladies 4
    Handbag designer 2
    2 leather handbag
    Laptop 2
    Desktop computers 2
    Memory system 1
    1 barcode readers
    1 portable barcode readers
    1 hand-crafted leather wallets
    1 leather credit card holders
    Start ladies 1
    1 ladies sandals

    It would be great if I can achieve in a single SQL.

    My database size is also great arround 1.5 million records and on an average about 10 produced by the company

    Concerning
    Malice

    Hello

    [This thread | http://forums.oracle.com/forums/thread.jspa?threadID=717813&tstart=25] shows how to split a delimited (like your products column) parts list, one line per element.
    There is a solution for Oracle 9. In Oracle 10 (and more) that the solution (using SUBSTR and INSTR) will still work, but I recommend to use

    REGEXP_SUBSTR ( products
                  , '[^,]+'
                  , 1
                  , n
                  )  AS product
    

    Instead, to get the item of the n - th from the products in the list separated by commas.

    Once you have divided the column of the goods in parts, the main request is just

    SELECT    product
    ,         COUNT (*)  AS no_of_companies
    FROM      subquery
    GROUP BY  product
    ORDER BY  no_of_companies  DESC
    ,         product;
    
  • Need help to write a sub query

    Our environment - Oracle 10 g

    Hi all
    Need help to write a sub query to reach him here are examples of data using which iam trying to replace the value column in the table based on two other columns in the same table

    Examples of data

    ClaimNo flag LineNo Procedurecode
    100 01 N MN4567
    100 02 Y 7863
    100 03 N MN8976
    100 04 Y 9000
    101 01 Y 8954
    101 02 N MN6754
    101 03 N MN7654
    101 04 Y 8976
    102 01 Y 1234
    102 02 Y 2345
    102 03 Y 3456
    102 03 Y 4567

    Each column of ClaimNo has several rows of data. But if column procedurecode for a claimNo starts with MN then all values associated with the claimno for the flag column should replace N

    If the data must become like below

    ClaimNo flag LineNo Procedurecode
    100 01 N MN4567
    100 02 N 7863
    100 03 N MN8976
    100 04 N 9000
    101 01 N 8954
    101 02 N MN6754
    101 03 N MN7654
    101 04 N 8976
    102 01 Y 1234
    102 02 Y 2345
    102 03 Y 3456
    102 03 Y 4567


    Thank you

    See the example:

    with t as (
                  select 100 ClaimNo, '01' LineNo, 'N' Flag, 'MN4567' Procedurecode from dual
        union all select 100, '02', 'Y', '7863' from dual
        union all select 100, '03', 'N', 'MN8976' from dual
        union all select 100, '04', 'Y', '9000' from dual
        union all select 101, '01', 'Y', '8954' from dual
        union all select 101, '02', 'N', 'MN6754' from dual
        union all select 101, '03', 'N', 'MN7654' from dual
        union all select 101, '04', 'Y', '8976' from dual
        union all select 102, '01', 'Y', '1234' from dual
        union all select 102, '02', 'Y', '2345' from dual
        union all select 102, '03', 'Y', '3456' from dual
        union all select 102, '03', 'Y', '4567' from dual
    )
    select
        claimno,
        lineno,
        flag,
        case
          when count(decode(substr(procedurecode,1,2),'MN',1)) over(partition by claimno)>0
            then 'N'
          else flag
        end new_flag,
        procedurecode
    from t
    

    Kind regards
    Sayan M.

  • I need help to write a script that detects the first instance of a paragraph style and then change

    I need help to write a script that detects the first instance of a paragraph style and then he goes to a different paragraph style.  I don't necessarily need someone to write all this, by the biggest problem is to find how to find just the first instance of the paragraph style.  Any help would be greatly appreciated, thank you!

    Hello

    then try this with your active doc:

    ....................

    myDoc var = app.activeDocument;

    mStyle var = myDoc.paragraphStyles.item ("PS_NameToFind"); change the name to paraStyle

    var mStyle_1 = myDoc.paragraphStyles.item ("PS_NameToChange"); change the name to paraStyle

    var mFrames = myDoc.pages.everyItem ().textFrames.everyItem () .getElements ();

    app.findTextPreferences = null;

    app.findTextPreferences.appliedParagraphStyle = mStyle;

    for (var k = 0; k)< mframes.length;="">

    {

    currFound = mFrames [k] .findText ();

    If (currFound.length > 0)

    currFound [0] .paragraphs [0] .appliedParagraphStyle = mStyle_1;

    }

    app.findTextPreferences = null;

    ................

    Rgds

  • Need help to write a SQL query complex

    I have the source tabe as below

    -> SOURCE_TABLE
    NAME     CUST_ID     SVC_ST_DT     SVC_END_DT 
    TOM        1               31/08/2009      23/03/2011 
    DOCK       2               01/01/2004      31/05/2010 
    HARRY      3               28/02/2007      31/12/2009 
    I want to load as target table below
    -> TARGET_TABLE
    NAME     CUST_ID                     SVC_ST_DT      SVC_END_DT 
    TOM      1           31/08/2009      31/12/2009 
    TOM      1           01/01/2010      31/12/2010 
    TOM      1           01/01/2011      23/03/2011 
    DOCK      2           01/01/2004      31/12/2004 
    DOCK      2           01/01/2005      31/12/2005 
    DOCK      2           01/01/2006      31/12/2006 
    DOCK      2           01/01/2007      31/12/2007 
    DOCK      2           01/01/2008      31/12/2008 
    DOCK      2           01/01/2009      31/12/2009 
    DOCK      2           01/01/2010      31/05/2010 
    HARRY      3           28/02/2007      31/12/2007 
    HARRY      3           01/01/2008      31/12/2008 
    HARRY      3           01/01/2009      31/12/2009 
    Is it possible to write a SQL query that returns the data in the same way above the target table.

    Published by: AChatterjee on April 30, 2012 07:14

    Published by: AChatterjee on April 30, 2012 07:14

    Or like this...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 'TOM' as NAME, 1 as CUST_ID, date '2009-08-31' as SVC_ST_DT, date '2011-03-23' as SVC_END_DT from dual union all
      2             select 'DOCK', 2, date '2004-01-01', date '2010-05-31' from dual union all
      3             select 'HARRY', 3, date '2007-02-28', date '2009-12-31' from dual)
      4  --
      5  -- end of test data
      6  --
      7  select name, cust_id, svc_st_dt, svc_end_dt
      8  from (
      9        select name
     10              ,cust_id
     11              ,greatest(svc_st_dt, add_months(trunc(svc_st_dt,'YYYY'),yr*12)) as svc_st_dt
     12              ,least(svc_end_dt, add_months(trunc(svc_st_dt,'YYYY'),(yr+1)*12)-1) as svc_end_dt
     13        from t
     14             cross join (select rownum-1 as yr
     15                         from   dual
     16                         connect by rownum <= (select extract(year from max(svc_end_dt)) - extract(year from min(svc_st_dt)) + 1 from t)
     17                        )
     18       )
     19  where svc_st_dt <= svc_end_dt
     20* order by 2, 3
    SQL> /
    
    NAME     CUST_ID SVC_ST_DT            SVC_END_DT
    ----- ---------- -------------------- --------------------
    TOM            1 31-AUG-2009 00:00:00 31-DEC-2009 00:00:00
    TOM            1 01-JAN-2010 00:00:00 31-DEC-2010 00:00:00
    TOM            1 01-JAN-2011 00:00:00 23-MAR-2011 00:00:00
    DOCK           2 01-JAN-2004 00:00:00 31-DEC-2004 00:00:00
    DOCK           2 01-JAN-2005 00:00:00 31-DEC-2005 00:00:00
    DOCK           2 01-JAN-2006 00:00:00 31-DEC-2006 00:00:00
    DOCK           2 01-JAN-2007 00:00:00 31-DEC-2007 00:00:00
    DOCK           2 01-JAN-2008 00:00:00 31-DEC-2008 00:00:00
    DOCK           2 01-JAN-2009 00:00:00 31-DEC-2009 00:00:00
    DOCK           2 01-JAN-2010 00:00:00 31-MAY-2010 00:00:00
    HARRY          3 28-FEB-2007 00:00:00 31-DEC-2007 00:00:00
    HARRY          3 01-JAN-2008 00:00:00 31-DEC-2008 00:00:00
    HARRY          3 01-JAN-2009 00:00:00 31-DEC-2009 00:00:00
    
    13 rows selected.
    
  • Need help to write a sql

    Hi all

    I have a table with 2 fileds, say Patch, Applied_date

    Table example is below:

    Patch Applied_date
    ==================
    111 1 January 10
    222 1st February 10
    333 1 March 10
    444 2 January 10
    555 1st January 12
    666 3 January 10


    I want a query to display the output as below.

    I have search for "where patch in (111,222,777,888).

    I expect the output to be


    patch Applied_date
    ================
    111 1 January 10
    222 1st February 10
    777 not applied * 777 is not in the table, I want the applied to the display a date not applied *.
    not applied 888 * 888 dosent column exists in the table, even in this case I want in the result and its
    column (Applied_date) corresponding apply do not.


    Can someone write a sql to do this.

    I can write a PL/SQL. I want a sql.

    Thank you
    Prasad

    Published by: user13062453 on February 18, 2012 12:10

    Create list of patches in a table and use an outer join:

    with patch as (
                   select 111 patch,to_date('1-Jan-10','dd-mon-rr') applied_date from dual union all
                   select 222,to_date('1-Feb-10','dd-mon-rr') from dual union all
                   select 333,to_date('1-Mar-10','dd-mon-rr') from dual union all
                   select 444,to_date('2-Jan-10','dd-mon-rr') from dual union all
                   select 555,to_date('1-Jan-12','dd-mon-rr') from dual union all
                   select 666,to_date('3-Jan-10','dd-mon-rr') from dual
                  ),
         list  as (
                   select 111 patch from dual union all
                   select 222 from dual union all
                   select 777 from dual union all
                   select 888 from dual
                  )
    select  l.patch,
            nvl(to_char(p.applied_date,'dd-Mon-yy'),'Not applied') applied_date
      from      patch p
            right join
                list l
              on l.patch = p.patch
    /
    
         PATCH APPLIED_DAT
    ---------- -----------
           111 01-Jan-10
           222 01-Feb-10
           777 Not applied
           888 Not applied
    
    SQL> 
    

    SY.

  • Need help to write to Oracle and SQL Server in the Oracle triggering

    We have a third which feeds data for us. Their client application feeds directly to some source tables in our Oracle database 10g. We have triggers on those tables that sort and treat lines as they come.

    We have a new operation and try to write some of these incoming data now to a SQL Server database through heterogeneous services - essentially the same exact data in two databases. I have a related database that works very well for the selection, but I've never tried to write Oracle PL/SQL to write in a DB SQL Server 2008. My first attempt was met with the following error: "ORA-02047: impossible to join the current distributed transaction.

    I found another thread where they say that the only way to do it is by using a stand-alone transaction, but they do not give an example. Here is the section of relaxation that I use:
      select to_char(new_date,'MM-DD-YYYY') into sql_txt from dual;
      insert into mancamp_location@sqlweb
           ("UnitID", "ManCampID", "Lat", "Long", "UpdateDT", "VehSpeed", "VehDirection", "Landmark")
        values (v_truck, f_unit, f_lat, f_long, sql_txt, f_spd, f_dir, f_ldmk);
    Can someone point me to a way to accomplish this simple insertion?

    An example of a standalone trigger is:

    Suppose you have a table in Oracle:

    CREATE TABLE emp_sal
    (
    EMPNO NUMBER 4,
    SAL NUMBER (7.2));

    and a similar table in a SQL server:
    SQL Server:

    CREATE TABLE emp_sal
    (
    EMPNO NUMERIC (4).
    SAL NUMERIC (7.2));

    Then, you can create an insert trigger that replicates the data:
    CREATE OR REPLACE TRIGGER dg4odbc_repl AFTER INSERT ON emp_sal
    FOR EACH LINE
    DECLARE
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
    INSERT INTO 'emp_sal"@MSODBCSQLSERVER_DG4ODBC_EMGTW_1123_DB '.
    VALUES (: new.empno,: new.sal);
    COMMIT;
    END;
    /

    -Note the validation, otherwise risk of ORA-6519

    When you now insert a record into the Oracle database:
    insert into emp_sal values (1234, '1200,89');
    the trigger is activated and inserts the record in SQL Server:
    Select * from 'emp_sal"@MSODBCSQLSERVER_DG4ODBC_EMGTW_1123_DB;
    EMPNO, SAL
    ----- -------
    1234 1200.89

    It works fine when you post data insert, but as soon as restore you the insert only data Oracle will be cancelled - data will remain as long as the independent transaction dedicated to its SQL Server insert:

    insert into emp_sal values (1384, '1200,89');
    Rollback;
    Select * from emp_sal;
    EMPNO, SAL
    ----- -------
    1234 1200.89

    Select * from 'emp_sal"@MSODBCSQLSERVER_DG4ODBC_EMGTW_1123_DB;
    EMPNO, SAL
    ----- -------
    1234 1200.89
    1384 1200.89

    So I strongly recommend to use the DG4MSQL gateway which is able to participate in distributed transactions and allows validation/restore transactions.

    DG4ODBC lie on OTN (http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html-online check out the "See all" link for your favorite platform), cloud of delivery of software Oracle (https://edelivery.oracle.com/) or "My Oracle Support". My Oracle support welcomes the latest version 11.2.0.3. In My Oracle Support goto patches and updates, then search for 11.2.0.3 data set Patch 10404530patch: 11.2.0.3.0 PATCH SET for ORACLE database SERVER, choose your preferred platform and see the Readme which CD contains the gateway software.

    Published by: kgronau on April 24, 2012 08:44

  • Need help on the regular expressions and query

    Hi guru s, I hope that you all made great!

    I have a scenario where I need to insert data into the table.

    I have three scenarios:
    select 'Kodali,Raj,S' str from dual
    union 
    select 'Alex Romano' from dual
    union 
    select 'ppppp' from dual
    
    Alex Romano
    Kodali,Raj,S
    ppppp
    What I want is now.

    1 Alex Romano
    is there space between the chain and then I want to insert in the last name and first name columns
    2 Xavier, Raj, S
    If there is a comma between the chain and I want to insert in the last name, first name and middle name
    3. If there is one channel then insert even in first name and last name.

    I wrote the request more early to manage only by commas and now I'm trying but not able to use this all scenarios
    Can you please help me.
    WITH t AS (
     
    select 'Kodali,Raj,S' str from dual
    union 
    select 'Alex Romano' from dual
    union 
    select 'ppppp' from dual
    
    ) 
    select DECODE(trim(a),NULL,'a',trim(a)),DECODE(trim(b),NULL,'b',trim(b)),decode(trim(c),NULL,'c' ,trim(c)) 
    from 
     (
      SELECT max(decode(level,1,regexp_substr(str,'[^,]+',1,level))) a --INTO lFNAME
              , max(decode(level,2,regexp_substr(str,'[^,]+',1,level))) b --INTO lLNAME
              , max(decode(level,3,regexp_substr(str,'[^,]+',1,level))) c --INTO lMNAME       
       FROM   t
      CONNECT BY regexp_substr(str,'[^,]+',1,level) IS NOT NULL
      GROUP BY str
    ) ;
    Currently I put a b and c if its null value.


    Thanks in advance!

    Hello
    You can do what you asked for in pure SQL like this:

    WITH     got_pos          AS
    (
         SELECT     str
         ,     INSTR (str, ',')     AS comma_pos
         ,     INSTR (str, ' ')     AS space_pos
         FROM     t
    )
    SELECT    str
    ,       CASE
               WHEN  comma_pos > 0
               THEN  REGEXP_SUBSTR (str, '\w+', 1, 2)
               WHEN  space_pos > 0
               THEN  SUBSTR (str, 1, space_pos - 1)
               ELSE  str
           END     AS fname
    ,       CASE
              WHEN  comma_pos > 0
              THEN  REGEXP_SUBSTR (str, '\w+', 1, 3)
              ELSE  TRIM (REGEXP_SUBSTR (str, ' \w+ '))
           END     AS mname
    ,       CASE
               WHEN  comma_pos > 0
               THEN  SUBSTR (str, 1, comma_pos - 1)
               ELSE  REGEXP_SUBSTR (str, '\w+$')
           END     AS lname
    FROM       got_pos
    ORDER BY  str
    ;
    

    But look how it is difficult, even for this simple example of data.

    I suggest you write a PL/SQL function to analyze the name. It will be much easier to deal with a combination of spaces and commas, the names of more than 3 words, etc.

  • Need help to write sql query

    I am trying to write the SQL for a single recordset.

    I have a table with all the info from the standard article and an item_colorID.

    I have a table with 2 columns, item_colorID and color_ID color_lookup

    I have a table with 2 columns, color_ID colors and color

    I want to join the tables and filter it so that a repeat region shows dynamic data by the name of article, thumb, description, price

    and also a dynamic list/menu populated by color

    filtered so that each element is in the list/menu only available element colors.

    I have tried different variations of this sql

    SELECT * items INNER JOIN color_lookup ON color_lookup.item_colorID = items.item_colorID INNER JOIN colors ON colors.color_ID = color_lookup.color_ID WHERE items.itemCatID = 3 ORDER BY items.itemName

    but the list/menu shows each color choice, multiplied by the number of items in this color

    That is to say white will show 80 + times.

    Thanks for your help,

    Jim balthrop

    Hi JB, I think I understand the situation, but of course, I'm not familiar with the interface of the cart software you are using. It seems that you will not be able to use the choice "research from the recordset" because the color is a different Recordset. You can't really understand the color in the main recordset because it would cause the main repeating region show the item once for each available color, which is not what you want.

    I also see that the drop-down color is in its own form. If you have placed this process in the main form, would be the behavior recoginize it and treat it differently? In other words, the cart accepts entry options outside the main form element it uses:

    
    

    I don't know that the shopping cart software contains other methods to add to the cart you can be forced to use.

    What shopping cart software are you helping? They have a forum which you could get more targeted assistance?

  • Need help to write the SQL query

    Hello
    Please help me to write a query. My requirement is as below.

    Hello
    I have a table say XYZ in the following format.

    product_id local min_order_quntity
    ========================================
    1 en 10
    1 ch 10
    2 en 20
    2 ch 20
    3 en 30
    3 ch 30
    4 en 40
    4 NC 10

    Now I want to find the product_id where min_order_quantity is different for cn and locale

    now I want the result of the following

    product_id local min_order_quantity
    =============================================
    4          en          40
    4 ch 10

    This is different for local in and cn for product_id 4 min_order_quantity

    min_order_quantity should be the same for both the locale(en,ch) for any product_id.

    I want to find the product_id where min_order_quantity is different for ch and fr local

    Thank you..

    Hello

    This query should do the job

    select * from xyz t1
    where exists ( select 1 from xyz t2 where t2.product_id = t1.product_id and
                   t2.locale != t1.locale and t2.min_order_quantity != t1.min_order_quantity );
    

    See you soon

  • Need to write a different SQL query

    Oracle version: 11.2.0.4

    create visitors from the table (name varchar2 (10), dated $vdate);

    Insert values ('John', sysdate-3) visitors;

    Insert values ('John', sysdate-2) visitors;

    Insert values visitors ('John', sysdate + 1);

    Insert values visitors ('Thomas', sysdate-5);

    Insert values visitors ('Thomas', sysdate-4);

    Insert values visitors ('Thomas', sysdate + 2);

    Insert values visitors ('Adam', sysdate + 1);


    Now I need to find the max for each visitor with the name $vdate. I wrote the query below and I'm
    My expected results.

    My query:

    Select * from (name, $vdate, dense_rank (select) on mxdate (partition by name $vdate desc order)
    visitors)
    where mxdate = 1;

    Output:

    NAME $VDATE
    John May 14, 2015
    Thomas may 15, 2015
    Adam, 14 may 2015

    Can someone write this query using the EXISTS or NOT EXISTS with below terms?

    1. without using the aggrgeate function
    2. without using the analytic function

    Thanks for your help in advance...

    Note: This is not the original data. This is only the test data...

    Something like

    Select * from v1 visitors

    where does not exist (select 1 of visitors v2 where v1.name = v2.name and v1.vdate<>

    NOT TESTED.

  • need help to write sql code

    Hi all

    I need to write a sql that retrieves data from the status table and check for this time in the ESHIFT table if the flag was or not. If is there, then it will keep the record as it is Furthermore, there

    did not understand at the time the flag was N suppose ESHIFT table has one record where you N 13:00:01-13:30 then the status register which is 13:00-13:59 min 59 s, we should get 13:00 - 13: records of 00:00 1 and 2 of 13:30:01-13:59 min 59 s

    create table ESHIFT (From_date date, date, to_date, flag varchar2 (2));

    insert into ESHIFT values (' 1 February 12 09:00 ", February 1, 12 13:20 ', 'Y');

    insert into ESHIFT values (' 1 February 12 13:20:01 ", 1 February 12 13:30 ',' don't);

    insert into ESHIFT values (' 1 February 12 13:30:01 ", February 1, 12 16:00 ', 'Y');

    SELECT * from eshift;

    create table status (date of From_date, to_date date, status number);

    insert into values of status (1 February 12 11:00 ', February 1, 12 12:00 ', 1);

    insert into values of status (1 February 12 12:00:01 ', February 1, 12 12:20 ', 2);

    insert into status values ("1 February 12 12:20:01", 1 February 12 12:59:59 ', 1);

    insert into status values ("1 February 12 13:00", February 1, 12 13:59:59 ', 1);

    insert into status values ("1 February 12 14:00", February 1, 12 14:59:59 ', 2);

    SELECT * STATUS;

    In the case above should get sql

    1 FEBRUARY 12 11:00 1ST FEBRUARY 12 12:00 1

    FEBRUARY 1ST, 12 12:00 1ST FEBRUARY 12 12:20 2

    FEBRUARY 1ST, 12 12:20:01, 1 FEBRUARY 12 12:59:59 1

    FEBRUARY 1ST, 12 13:00 1ST FEBRUARY 12 13:20 1

    FEBRUARY 1ST, 12 13:30 1 FEBRUARY 12 13:59:59 1

    FEBRUARY 1ST, 12 14:00 1 FEBRUARY 12 14:59:59 2

    It will be really great if someone can help me how I can get the desired result.

    Thank you very much in advance.

    Please provide instructions creating table and data. It makes it so much easier to answer.

    I think you want:

    Select (s.from_date, e.from_date) greatest from_date, less (s.to_date, e.to_date) to_date, s.status

    s status e eshift join on s.from_date < e.to_date="" and="" s.to_date=""> e.from_date and e.flag = 'Y '.

    order by 1

  • Need help to write the query to extract the value of the previous row - Lag not help


    Hello

    I created follwing table.

    Create table test

    (number of fi,

    number of fo_fv

    number of jup_fv

    action varchar2 (10)

    );

    insert into TEST(1,1,1,'LOAD');

    Insert into TEST (2, NULL, 2, "ROLL");

    insert into TEST(3,,3,'ROLL');

    insert into TEST(4,,4,ROLL);

    insert into TEST (5,2,5,LOAD);

    I want the result of the query as below:

    FI FO_FV JUP_FV ACTION

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

    1          1                    1                    LOAD

    2          1                    2                    ROLL

    3          1                    3                    ROLL

    4          1                    4                    ROLL

    5          2                    5                    LOAD

    Help, please.

    Thank you!

    SQL > select fi
    2, max (fo_fv) on fo_fv (fi control)
    3, jup_fv
    4, action
    5 of the test;

    FI FO_FV JUP_FV ACTION
    ---------- ---------- ---------- ----------
    1 1 1 LOAD
    ROLL OF 2 1 2
    3 1 3 ROLL
    4 1 4 ROLL
    5 2 5 LOAD

    OR

    SQL > select *.
    2 test
    model 3
    Dimension 4 by (fi)
    5 measures (fo_fv, jup_fv, action)
    6 rules
    7   (
    8 fo_fv [any] = case when fo_fv [cv ()] is null
    9. can fo_fv [cv () - 1]
    10 fo_fv [cv () else]
    11 end
    (12);

    FI FO_FV JUP_FV ACTION
    ---------- ---------- ---------- ----------
    1 1 1 LOAD
    ROLL OF 2 1 2
    3 1 3 ROLL
    4 1 4 ROLL
    5 2 5 LOAD

  • need help to write a conditional query recordset

    I have two fields or not in the database. VeteranMarker and VeteranNoMarker. Answering one can be Y or N.
    I want to write a statement for my detail page where there is a label "veteran? If VeteranMarker or VeteranNoMarker has a Y in the database, then I want to display "YES" next to the label of "veteran? If neither has a Y, then I want to say 'NO '.

    The recordset is called DetailRS1, the fields would be so (I think) DetailRS1.VeteranMarker and DetailRS1.VeteranNoMarker.

    I have no idea how to write a conditional statement to achieve this.

    Thanks in advance,
    Miriam

    I think I have it solved. Here is the code, and it seems to work. If this is correct, I hope it can help someone else too.

  • Need help to write a MySQL query that returns only the peer matching records

    Because I don't know how to explain it easily, I use the table below as an example.

    I want to create a MySQL query that returns only the records that match counterparts where 'col1' = 'ABC '.

    Notice the ' ABC / GHI' record does not have a Counter-match ' GHI / ABC' record. This record must not be returned because there is no Counter-Party correspondent. With this table, the ' ABC / GHI' record should be the one returned in the query.

    How can I create a query that will do it?


    ID | col1 | col2
    --------------------
    1. ABC | DEF
    2. DEF | ABC
    3. ABC | IGS
    4. DEF | IGS
    5. IGS | DEF


    * Please let me know if you have no idea of what I'm trying to explain.

    I wanted to just the results where col1 = ABC, but I already got the answer I needed on another forum. Thank you anyway.

    SELECT a.col1,
    a.col2
    FROM table_name AS a
    LEFT OUTER
    Table_name JOIN b
    ON b.col1 = a.col2
    AND a.col1 = b.col2
    WHERE b.col1 IS NOT NULL AND a.col1 = 'ABC '.

Maybe you are looking for

  • Satellite Pro L300-1AF fails to start

    I have a Toshiba Satellite Pro L300-1AF that won't start, it stopped working a few weeks ago and I tried startup repair and things, and nothing seemed to work just kept loading a black screen with a cursor but nothing else. After a little more resear

  • 2 beeps on startup and the white screen - Satellite P300 - 19 p

    Hi guys,. I installed an Express card yesterday and he did all sorts of havoc (IRQ conflicts, hook etc.). I went to reboot this morning and he is now just give me 2 beeps and nothing on screen. I watched the phoenix bios beep codes, but it is not lis

  • Changed networking, now I can't connect!

    My other computer is a work computer, which I use at home. I was trying to set up a computer network at home on my work laptop (while I was at home), so that I could share files between two computers. If I remember correctly, the last thing I tried t

  • LC ST adapter Single mode

    Hello Currently, we have a cisco 2911 and were given to a single mode fiber of 1000/Mo with a ST connector from our supplier. I'm not able to find all the modules that support this type of interface for our router (most of them are LK). I don't have

  • Re - activate the password to a store?

    I did a store buy on my surface, and he has not asked my password. I would like to request a password, that sometimes I hand my Surface to someone else and I don't want buying them things. I went looking for this setting, but could not find. I think