Help to write a sql

Hi ,
I need help in putting a sql together for the ones listed below:
I have 2 queries and I need to put it in a format that I can use to run my sql .
select count(TRANSACTION_SID) from
(select EFFECTIVE_DATE, CREATION_DATE, ORG_SID, TRANSACTION_SID, DP_COUNT, DV_COUNT, TOTAL_SIZE,
rank() over ( partition by transaction_sid order by effective_date desc) rank
from Nightly_Inventory where effective_date<= to_date ('2008-12-03', 'yyyy/mm/dd') and org_sid='243')
where rank=1 and transaction_sid NOT IN (select transaction_sid from NIGHTLY_DELETED where effective_date<= to_date ('2008-12-03', 'yyyy/mm/dd'))
minus this:
select count(TRANSACTION_SID) from
NIGHTLY_DELETED where effective_date<= to_date ('2008-12-03', 'yyyy/mm/dd')
and transaction_sid IN (select TRANSACTION_SID) from
(select EFFECTIVE_DATE, CREATION_DATE, ORG_SID, TRANSACTION_SID, DP_COUNT, DV_COUNT, TOTAL_SIZE,
rank() over ( partition by transaction_sid order by effective_date desc) rank
from Nightly_Inventory where effective_date<= to_date ('2008-12-03', 'yyyy/mm/dd') and org_sid='243')
where rank=1 and transaction_sid NOT IN (select transaction_sid from NIGHTLY_DELETED where effective_date<= to_date ('2008-12-03', 'yyyy/mm/dd')) )
I would really really appreciate your help if I can get this working .
thanks .

Hi,
Do you want a single query that shows you the difference?
If so, you can do this:
SELECT    (
          select count(TRANSACTION_SID) from
          (select EFFECTIVE_DATE, CREATION_ ... -- your first query
          select count(TRANSACTION_SID) from
          NIGHTLY_DELETED where ... -- your second query
FROM      dual;There might be a much more efficient way, depending on what the two queries do.

Similar Messages

  • Help me write a SQL query; urgent

    Hi, can somebody please help me write a SQL query.
    I have 3 tables each with the same column names (Col1, Col2, Col3). Col1 is PK with Unique Constraint.
    I wanted to add values of Col2 and Col3 (from all 3 tables) and put it in a separate table (i.e aggregated) of all values found in Col1.
    Does anybody help me please ?
    thanks alot.

    Please don't mark your question as urgent. You've been around here long enough that you should know that it will not get your question anwered any faster, and may just irritate people into not answering at all.
    I'm not sure exactly what you want.
    Are you saying you want t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3 for the rows that have the same c1 in all three tables?
    If so, it would be like this, I think: insert into t4
    select t1.c1
    , t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3
    from t1, t2, t3
    where t2.c1 = t1.c1
    and t3.c1 = t1.c1If that's not what you want, please clarify.
    And next time maybe you should post your SQL question in a SQL forum.

  • Help to write the sql server 2012(business intelligence ) certification.

    Hi,
    I am planning to write the SQL SERVER 2012 certification exam.
    i want few more details...
    1. Examination code.
    2. how to prepare
    3. is there any dumps available.
    4. is there any books available for preparation.
    Please pass the details, it would be very help full for me..

    The Business Intelligence exams are:
    70-461: Querying Microsoft SQL Server 2012
    70-462: Administering Microsoft SQL Server 2012 Databases
    70-463: Implementing a Data Warehouse with Microsoft SQL Server 2012
    70-466: Implementing Data Models and Reports with Microsoft SQL Server 2012
    70-467: Designing Business Intelligence Solutions with Microsoft SQL Server 2012
    Ramesh Babu Vavilla MCTS,MSBI

  • Need help in writting the sql

    The sql
    select 'alter system kill session '||sid||','||serial#||';' from v$session where username= 'EV05';
    give the output in the below given form
    alter system kill session 69,38769;
    But i need the output to be
    alter system kill session '69,38769';
    Can some one re-writes the sql select statment,
    Thanks
    Naveen

    Naveen,
    This isn't the forum for help with writing SQL - rather with using the SQL Developer product. In future, I would suggest that you use the SQL and PL/SQL forum for these sorts of questions.
    However, to answer your question this time, you can include a ' in a string by having two together ie 'fred''s' will return the string fred's.
    The following SQL will give you the result you want:
    select 'alter system kill session '''||sid||','||serial#||''';' from v$session where username= 'EV05';

  • Help to write following SQL query?

    Hey, beginner hopes to get some help from pro's.
    Please write SQL query to select only green and yellow fruits that are in stock and output results sorted by fruit name in ascending order.
    Database name: warehouse
    Table name: Inventory
    id |   Fruit   | Color | stock
    1 |  apple   | green | 5
    2 | banana | yellow | 3
    3 | orange | orange | 1
    4 | lemon  | yellow  | 7
    5 |  pear   | green 
    | 0
    Thanks in advance!

    If your database and SQL server use default SQL Server collation which is case insensitive, then drop lower function from the suggested script and use 
    color in ('green', 'yellow')
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Help to write an sql query

    Hi everyone!
    I need some help in composing a query that would calculate the number of occurrences of '29-Feb' between 2 given dates (i.e. substitution variables).
    What I figured so far is a way too complex and don't work all the time. Also I do know, that calculating a leap year is a bit different than just year mod 4 = 0.
    I would appreciate very much if you help me to write this query or just give me a guess.
    SELECT TO_NUMBER(TO_CHAR(date2, 'YYYY')-TO_CHAR(date1, 'YYYY'))/4
    FROM
    (SELECT CASE
    WHEN MOD(TO_NUMBER(TO_CHAR(TO_DATE('&&date1', 'DD-Mon-RR'), 'RR')), 4) = 0
    THEN TO_DATE('&date1', 'DD-Mon-RR')
    ELSE(CASE
    WHEN MOD(TO_NUMBER(TO_CHAR(ADD_MONTHS(TO_DATE('&date1', 'DD-Mon-RR'), 12), 'RR')), 4) = 0
    THEN ADD_MONTHS(TO_DATE('&date1', 'DD-Mon-RR'), 12)
    ELSE(CASE
    WHEN MOD(TO_NUMBER(TO_CHAR(ADD_MONTHS(TO_DATE('&date1', 'DD-Mon-RR'), 24), 'RR')), 4) = 0
    THEN ADD_MONTHS(TO_DATE('&date1', 'DD-Mon-RR'), 24)
    ELSE(CASE
    WHEN MOD(TO_NUMBER(TO_CHAR(ADD_MONTHS(TO_DATE('&date1', 'DD-Mon-RR'), 12), 'RR')), 4) = 0
    THEN ADD_MONTHS(TO_DATE('&date1', 'DD-Mon-RR'), 36)
    END)
    END)
    END)
    END date1,
    CASE
    WHEN MOD(TO_NUMBER(TO_CHAR(TO_DATE('&&date2', 'DD-Mon-RR'), 'RR')), 4) = 0
    THEN TO_DATE('&date2', 'DD-Mon-RR')
    ELSE(CASE
    WHEN MOD(TO_NUMBER(TO_CHAR(ADD_MONTHS(TO_DATE('&date2', 'DD-Mon-RR'), 12), 'RR')), 4) = 0
    THEN ADD_MONTHS(TO_DATE('&date2', 'DD-Mon-RR'), 12)
    ELSE(CASE
    WHEN MOD(TO_NUMBER(TO_CHAR(ADD_MONTHS(TO_DATE('&date2', 'DD-Mon-RR'), 24), 'RR')), 4) = 0
    THEN ADD_MONTHS(TO_DATE('&date2', 'DD-Mon-RR'), 24)
    ELSE(CASE
    WHEN MOD(TO_NUMBER(TO_CHAR(ADD_MONTHS(TO_DATE('&date2', 'DD-Mon-RR'), 12), 'RR')), 4) = 0
    THEN ADD_MONTHS(TO_DATE('&date2', 'DD-Mon-RR'), 36)
    END)
    END)
    END)
    END date2
    FROM DUAL);
    UNDEFINE date1;
    UNDEFINE date2;

    Hi,
    Interesting problem!
    The query below looks at the 59th day after January 1 in each year.
    If that date was in February, then it was a leap year.
    If that date was not in February, then it was a common year.
    DEFINE     date1     = "TO_DATE ('07-11-1609', 'DD-MM-YYYY')"
    DEFINE     date2     = "TO_DATE ('06-11-2009', 'DD-MM-YYYY')"
    WITH     all_years AS
         SELECT     ADD_MONTHS ( TRUNC (&date1, 'YYYY')
                      , 12 * (LEVEL - 1)
                      ) + 59       AS dt
         FROM     dual
         CONNECT BY     LEVEL <= 1 + CEIL ( MONTHS_BETWEEN ( &date2
                                                         , &date1
                               / 12
    SELECT     COUNT ( CASE
                   WHEN  TO_CHAR (dt, 'MM') = '02'
                   THEN  1
              END
               )          AS leap_year_cnt
    FROM     all_years
    WHERE     dt     BETWEEN      &date1
              AND      &date2
    ;A less efficient (for what that's worth) way is to generate all dates between &date1 and &date2, and test each one to see if it is '02-29'.
    I'll leave that as an exercise to the reader.
    HINT: the coding is simpler than the query above. (In my prolix style, it took 10 lines. No sub-query is needed.)

  • Who can help me write a sql?

    Table T has a field F, I want to replace all oldstr with newstr in field F.
    for example: "abc oldstr end" will be updated to "abc newstr end".
    Thanks a lot

    I can't use PrepareStatement in "replace" function like in normal query, update sql command.
    when I do:
    sql: update T set F=replace(F, ?, ?) where F like ?
    pstmt.setString(1, oldstr);
    pstmt.setString(2, newstr);
    pstmt.setString(3, '%'+oldstr+'%');
    DB2 throws:
    DB2Exception: [IBM][CLI Driver][DB2/SUN] SQL0418N A statement contains a use of a parameter marker that is not valid. SQLSTATE=42610
    if I do it like :
    sql: update T set F=replace(F, 'oldstr', 'newstr') where F like ?
    pstmt.setString(1, '%'+oldstr+'%');
    it works well,
    it seems that I can't set parameter inside "replace" function, could anyone tell me how to do? Thanks

  • Help needed in writing SQL CASE or DECODE statement

    Hi experts,
    I need to write a SQL to select order_num, cntry_cde, prod_id and Qty by joining order_num on PROD_ORDER and PROD_ORDER_TXT.
    Here is my sample data
    PRODORDER_               
    order_num     cntry_cde     Prod_id     Qty
    100     US     A1     5
    101     US     A2     10
    102     AU     A3     4
    103     AU     A4     9
    104     IN     A5     3
    PRODORDER_TXT_               
    order_num     cntry_cde     Prod_id     
    100     US     A1     
    101     US     A2     
    102     NZ     A3     
    103     AU     A4     
    104          A5     
    Here is the requirement,
    1) If the cntry_cde in PROD_ORDER is same as cntry_cde in PROD_ORDER_TXT then select PROD_ORDER.cntry_cde (orders 100, 101, 103)
    2) If they are different, pick the country code from PROD_ORDER_TXT (order 102, AU <> NZ)
    3) If they are different and PROD_ORDER_TXT.cntry_cde is NULL, I cannot use it as cntry_cde in my report (order 104). It happenend just because of the bad data at source.
    I cannot avoid it. Then simply use the cntry_cde from PROD_ORDER
    Output expected
    100     US     A1     5
    101     US     A2     10
    102     NZ     A3     4 -- AU changed to NZ
    103     AU     A4     9
    104     IN     A5     3 -- IN retained as PROD_ORDER_TXT.cntry_cde is null
    sample table creation and insert statements are below
    create table prod_order
    (order_num number,
    cntry_cde CHAR(2),
    prod_id VARCHAR2(6),
    qty number)
    create table prod_order_txt
    (order_num number,
    cntry_cde CHAR(2),
    prod_id VARCHAR2(6))
    insert into prod_order values (100, 'US', 'A1',5);
    insert into prod_order values (101, 'US', 'A2',1);
    insert into prod_order values (102, 'AU', 'A3',4);
    insert into prod_order values (103, 'AU', 'A4',9);
    insert into prod_order values (104, 'IN', 'A5',3);
    insert into prod_order_txt values (100,'US','A1');
    insert into prod_order_txt values (101,'US','A2');
    insert into prod_order_txt values (102,'NZ','A3');
    insert into prod_order_txt values (103,'AU','A4');
    insert into prod_order_txt values (104,NULL,'A5');
    commit;
    Thanks for your help in advance
    Edited by: sarvan on Mar 28, 2012 1:39 PM

    Hello
    Thank you for posting all of the ddl and test data along with your expected output - very helpful!. One small point would be to remember to type {noformat}{noformat} before and after any section of code or data in your post so that formatting is retained.  Anyway, this should be a simple join and a combination of CASE and NVL...Select
    po.order_num,
    CASE
    WHEN po.cntry_cde != NVL(pot.cntry_cde,po.cntry_cde)
    THEN
    pot.cntry_cde
    ELSE
    po.cntry_cde
    END cntry_code,
    po.prod_id,
    po.qty
    FROM
    prod_order po
    JOIN
    prod_order_txt pot
    ON
    ( po.order_num = pot.order_num
    ORDER_NUM CN PROD_I QTY
    100 US A1 5
    101 US A2 1
    102 NZ A3 4
    103 AU A4 9
    104 IN A5 3
    5 rows selected.
    HTH
    David
    Edited by: Bravid on Mar 28, 2012 8:32 AM
    corrected !=                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Help needed in framing SQL query.

    Hi,
    I have table having following schema:
    PRODUCT_ID         INT
    DATE                   DATETIME
    ITEMS_SOLD         INT
    This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
    Any help to get the SQL query will be appreciated.
    Thanks,
    Akshay.

    PRODUCT_ID      DATE           ITEMS_SOLD
    1          10/10/2011     3
    1          11/10/2011     3
    1          12/10/2011     3
    1          13/10/2011     3
    1           16/10/2011     5
    2          10/10/2011     4
    2           11/10/2011     4
    2          12/10/2011     4
    2          13/10/2011     4
    2           14/10/2011     4
    2          15/10/2011     4
    2          16/10/2011     4
    Output:
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3                4     
    2          4               7
    Explanation of results:
    The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3               4     
    as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
    For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    2           4               7
    Other case where same PRODUCT_ID have different units sold on each day should be ignored.
    I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
    -Akshay.

  • Trying to write an SQL import script

    Hello All,
    I am trying to write a bulk importer for data for my clients and I am just about there. However I am running into a problem updating records in a second table.
    I want to do all this through the SQL Server for resource purposes.
    The SQL statement will go through the entire temp table (users to be added or updated) and compare it to the main existing table. First it will compare records and determine who are exactly the same (no changes) and then delete those records out of the temp table. Now it will find the records that are in the table (by employee ID), but have changes in their profiles (name, number, etc.).
    This is my problem:
    When I compare the phonenumbers in a separate table, which are connected by a sub_id. Example
    Main Table: (Fields) sub_id, fname, lname, address, groups, subgroups, etc.
    Phonenumbers Table: sub_id, account_id, sub_user_number, active
    Right now, I am performing update statements:
    -- Update sub_user_number
    print('Update sub_user_number');
    print('  -sub_user_number3');
    UPDATE WENS..SUBSCRIPTION
    SET sub_user_number = i.sub_user_number3
      FROM WENS_IMPORT..IMPORT_INSPIRON i INNER JOIN WENS..SUBSCRIPTION s
       ON i.misc1 = s.misc1
      LEFT JOIN WENS..ACCOUNT_USER_GROUPS g
       ON g.sub_id = s.sub_id
      WHERE s.account_id = @account_id
      AND isnull(i.sub_user_number, '') <> isnull(s.sub_user_number, '')
      AND g.group_id IN (@group_id)
    The problem is that if I have three numbers, it updates all three numbers with the same number.
    Ideally what I would like to do is completely delete the numbers and then re-enter them. For example:
    Perform a DELETE of all numbers out of PHONENUMBERS table where maintable.sub_id = temptable.sub_id
    LOOP through numbers found in temptable
    INSERT new number into PHONENUMBERS (sub_id, account_id, active, sub_user_number)
    END LOOP
    Therefore at the end of the loop, we will have entered three numbers (two that were originally in there and one that is new)
    Could someone help me with the SQL syntax that will work in SQL Server Query analyzer?
    Thank you VERY much for anything you all can do.

    LOOP through numbers found in temptable
    I have only skimmed this thread, but I would say do not loop unless it is truly needed.  Databases are designed to work best with "sets" of information. So it is usually more efficient to process a group of records than one record at a time.
    What I usually do with imports is run a series of bulk updates on my #temp table(s) to identify which items are "new" which ones are "changed". When finished I can easily JOIN to the base tables and do a single UPDATE for changed records and INSERT for new records.  Usually a lot more efficient than looping one record at a time.
    I want to do all this through the SQL Server for resource
    purposes.
    BTW: Not to ignore your question, but database questions are usually best answered in a database forum (in your case MS SQL).  Because once you get the information into the #temp table, it is strictly sql from there and any database guru could assist. They do not have to know anything about CF ;-)
    Message was edited by: -==cfSearching==-

  • How can I write a SQL statement which checks if a table exists?

    How can I write a SQL statement which tells me whether a table exists?

    execute an sql query: select * from <tablename>
    catch the exception n check whether the erroe code
    matches the one that occurs for table doesn't exist
    that's itHow is your answer any different from the one given in the first reply?
    It isn't.
    As WorkForFood says DatabaseMetaData has a bunch of methods for getting information about tables but this is more useful when you don't know the names of any of the tables.. it sounds like you do so I would concur SELECT from table is probably the quickest way to go. If it helps the Xopen error should be either S1000 or 42S01 (I think) but I would try and see if there is a specific vendor code for table not found/not exists error and check for that.

  • Please help me with this SQL query

    I am practicing SQL queries and have come across one involving fetching data from 3 different tables.
    The three tables are as below
    <pre>
    Country
    location_id          country
    loc1          Spain
    loc2          England
    loc3          Spain
    loc4          USA
    loc5          Italy
    loc6          USA
    loc7          USA
    </pre>
    <pre>
    User
    user_id location_id
    u1 loc1
    u2 loc1
    u3 loc2
    u4 loc2
    u5 loc1
    u6 loc3
    </pre>
    <pre>
    Post
    post_id user_id
    p1 u1
    p2 u1
    p3 u2
    p4 u3
    p5 u1
    p6 u2
    </pre>
    I am trying to write an SQL query - for each country of users, display the average number of posts
    I understand the logic behind this that we first need to group together all the locations and then the users belonging to one country and then find the average of their posts.
    But, i'm having a difficulty in putting this in SQL form. Could someone please help me with this query.
    Thanks.

    select
    country.country,
    count(*) Totalpostspercountry,
    count(distinct post.user_id) Totaldistincuserspercountry,
    count(*)/count(distinct post.user_id) Avgpostsperuserbycountry
    from
    country, muser, post
    where country.location_id = muser.location_id
    and muser.user_id = post.user_id
    group by country.country
    The output is like this for your sample data - hope this is what you were looking for :)
    COUNTRY,TOTALPOSTSPERCOUNTRY,TOTALDISTINCUSERSPERCOUNTRY,AVGPOSTSPERUSERBYCOUNTRY
    England,1,1,1,
    Spain,5,2,2.5,

  • No Read or Write into SQL Database in Distribution configuration (Urgent)

    Hello
    I have build an application that have use database. It works fine when in debug mode but when i make installer then there is no read or write operation into database. I am using SQL Toolkit 2.2 and LabWindows 2010 and SQL Server 2008.
    Kindly help me because now i want to handover application to my client.
    Best Regards
    Umer

    Hi Umer
    This is a standard issue with the SQL toolkit. Read the Help under Library Reference->SQL Toolkit Library->SQL Language Reference->Distributing an SQL Toolkit Executable or DLL.
    It says:
    "Distribute the following files with an executable or DLL that uses SQL Toolkit functions.
    You must use the CVISQLShared.msm merge module to install support for the LabWindows/CVI SQL Toolkit. The CVISQLShared.msm merge module is located in the Program Files\Common Files\Merge Modules directory.
    Note  Use the CVISQLShared_x64.msm merge module for 64-bit executables and DLLs.
    Include the sqldistsupp.exe and sqldistsupp.dsn files when you create a LabWindows/CVI distribution in order to install required database components. Set sqldistsupp.exe as the program to run after installation in the distribution.
    The sqldistsupp.exe program, located in the [CVIDIR]\redist directory, creates a system data source name using sqldistsupp.dsn. The sample sqldistsupp.dsn file creates a data source called CVI SQL Samples, which works with the Microsoft Access ODBC driver. You can use the tokens [WindowsDirectory], [WindowsSystemDirectory], [CVISQLInstallDirectory], and [AppInstallDirectory] in the .dsn file. At installation time, the sqldistsupp.exe program replaces these tokens with the proper paths.
    Notes
    For 64-bit executables and DLLs, use the sqldistsupp.exe and sqldistsupp.dsn files in the [CVIDIR]\redist\x64 directory.
    [CVISQLInstallDirectory] is the directory containing sqldistsupp.exe and is equivalent to [AppInstallDirectory].
    The location of [CVIDIR] varies depending on the latest version of LabWindows/CVI you have installed.
    Version
    [CVIDIR] Folder Location
    LabWindows/CVI not installed
    National Instruments\Shared\CVI
    LabWindows/CVI 8.1.1 or earlier
    National Instruments\CVIxx
    LabWindows/CVI 8.5 or later
    National Instruments\Shared\CVI
    Now, why this essential information is buried is the entirely counter-intuitive SQL Language Reference section I do not know.
    Neither do I understand why the install builder does not do this automatically.
    Anyone from NI care to comment?

  • Need help in rewriting a sql query

    Can any one please tell me if there is any utility that can help me correcting the sql I have I need to tune the query as its taking lot of time. I want to use some tool that will help me re-formating the query.
    Any help in this regard will be highly appreciated.

    If you think that Oracle SQL Tuning Tools like SQL Tuning Advisor and SQL Access Advisor are not helping.
    You might look into thrid party tools like Quest- SQL Navigator and TOAD.
    But I don't advise this based on the following:
    Re: Oracle Third Party Tools and Oracle Database
    Oracle have enough tools of its own to satisfy the various needs.
    Adith

  • How to write this SQL query

    We have a table, the structure as below: (I put a blank row in the middle to make it clear)
    Product_ID     Retailer     Retail_Price
    1001          A          1.2
    1001          B          1.5
    1001          C          1.4
    1002          B          2.0
    1002          C          2.1
    1002          E          1.8
    1002          F          2.0
    1003          A          1.7
    1003          C          1.5
    Basically we use the table to compare the retail price for different retailers in terms of different products. My customer asked me to give a report based on above table but only shows the retail prices which contain retailer A.
    For example, on above table I need to give a report like below:
    Product_ID     Retailer     Retail_Price
    1001          A          1.2
    1001          B          1.5
    1001          C          1.4
    1003          A          1.7
    1003          C          1.5
    Can anybody give some ideas on how I should write a SQL to achieve this.
    Many thanks!

    SQL> create table product(
    2 Product_ID varchar2(10),
    3 Retailer varchar2(10),
    4 Retail_Price number(7,2)
    5 )
    6 /
    Table created.
    SQL> insert into product values('1001','A',1.2)
    2 /
    1 row created.
    SQL> insert into product values('1001','B',1.5)
    2 /
    1 row created.
    SQL> insert into product values('1001','C',1.4)
    2 /
    1 row created.
    SQL> insert into product values('1002','B',2.0)
    2 /
    1 row created.
    SQL> insert into product values('1002','C',2.1)
    2 /
    1 row created.
    SQL> insert into product values('1002','E',1.8)
    2 /
    1 row created.
    SQL> insert into product values('1002','F',2.0)
    2 /
    1 row created.
    SQL> insert into product values('1003','A',1.7)
    2 /
    1 row created.
    SQL> insert into product values('1003','C',1.5)
    2 /
    1 row created.
    SQL> select * from product
    2 /
    PRODUCT_ID RETAILER RETAIL_PRICE
    1001 A 1.2
    1001 B 1.5
    1001 C 1.4
    1002 B 2
    1002 C 2.1
    1002 E 1.8
    1002 F 2
    1003 A 1.7
    1003 C 1.5
    9 rows selected.
    SQL> select * from product where PRODUCT_ID in (
    2 select distinct PRODUCT_ID from product where RETAILER='A')
    3 /
    PRODUCT_ID RETAILER RETAIL_PRICE
    1001 A 1.2
    1001 B 1.5
    1001 C 1.4
    1003 A 1.7
    1003 C 1.5

Maybe you are looking for

  • My computer & itunes won't recognize my ipod nano is connected

    So my brother got an ipod nano, the the original version with only the colored front panel or whatever, and then I got am ipod nano, the second or newer version and we run them off of the same computer. Well his is no loger in use since it went throu

  • Acrobat 9: Error when PDF form submit with file attachment

    Hi all, Hope you can provide some help with my PDF form submit issue. I am getting this error "There is no PDDoc associated with this CosDoc." in Acrobat 9 (Reader and Pro) when I try to submit a PDF form with a file attachment field (the file is spe

  • DW CS4 Live View Not Working

    I have migrated within a week of buying DW CS3 to DW CS4 and have been spending the last 24 hours or so watching the excellent videos on lynda.com for CS4. I then decided to take the plunge and start producing my own content. The first thing I wanted

  • Header in flat file destination (ssis)

    Hi I am creating a header in the flat file destination which has some hard coded values and record count which will get its value from a variable assisgned to a row count transformation in the package. There is no problem in hard coded value but when

  • Transfer of appointments

    My transfer of appointments has succeeded since yesterday no longer with my Nokia 9300i. Synchronisation runs normally therefore that does he but there nothing is, however, transferred everything remains the same. Where can this hold course? Thanks