Please help me with this SQL query

I'm practicing of SQL queries and met one involving the extraction of data from 3 different tables.

The three paintings 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
loc1 U1
loc1 U2
loc2 U3
loc2 U4
loc1 U5
U6 loc3
< / pre >
< pre >


Publish
user_id post_id
P1 u1
P2 u1
U2 P3
P4 u3
P5 u1
P6 u2
< / pre >

I am trying to write a SQL query - for each country of the users, showing the average number of positions

I understand the logic behind all this that we must first consolidate all locations, and then the users in one country and then find the way to their positions.
But, I'm having a difficulty to this format SQL. Could someone help me please with this request.

Thank you.

Select
Country.Country,
Count (*) Totalpostspercountry,
Count (distinct post.user_id) Totaldistincuserspercountry,
count (*) / count (distinct post.user_id) Avgpostsperuserbycountry
Of
countries, have, post
where country.location_id = muser.location_id
and muser.user_id = post.user_id
Country.country group

The output is like this for your sample data - hope that's what you're looking for :)

COUNTRY, TOTALPOSTSPERCOUNTRY, TOTALDISTINCUSERSPERCOUNTRY, AVGPOSTSPERUSERBYCOUNTRY
In England, 1, 1, 1.
Spain, 5, 2, 2.5.

Tags: Database

Similar Questions

  • Please help me write this SQL query...

    Hi everyone,
    
    Please help me in this query.
    A patient can multiple types of Adresses (types P,M,D).If they have all the 3 types i need to select type: p and
    if they have (M and D) i need to select type M,and if they have only type D i have to select that.
    For each address i need to validate whether that particular address is valid or not (by start date and end date and valid flag)
    
    Patient table
    =============
    
    Patient_id          First_name    last_name
    
    1                   sanjay        kumar
    2                   ajay          singh
    3                   Mike          John
    
    
    Adress table
    ============
    
    address_id       patient_id       adresss       city       type       startdate        enddate      valid_flg
    
    1                   1             6222         dsadsa           P          01/01/2007       01/01/2010
    2                   1             63333        dsad             M          01/02/2006       01/01/2007      N
    3                   1             64564         fdf              M          01/01/2008       07/01/2009      
    4                   1             654757       fsdfsa          D          01/02/2008       09/10/2009  
    5                   2             fsdfsd       fsdfsd            M          01/03/2007       09/10/2009   
    6                   2             jhkjk        dsad              D          01/01/2007       10/10/2010   
    7                   3             asfd         sfds               D          01/02/2008       10/10/2009      
    
    
    output
    =====
    
    1        sanjay       kumar            6222       dsadsa      P          01/01/2007        01/01/2010     
    2        ajay         singh            fsdfsd     fsdfsd       M          01/03/2007        09/10/2009 
    3        mike         john              asfd       sfds        D          01/02/2008        10/10/2009
    Thanks in advance
    Phani

    Hello, Fabienne,.

    This race for you (twisted code of Sarma):

    SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate
     FROM (
      SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate,
                 ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1
                                                                          WHEN  'M' THEN 2
                                                                          WHEN  'D' THEN 3
                                                                        END) rn
        FROM  patient p
        JOIN  address a ON (p.patient_id = a.patient_id )
       WHERE NVL(valid_flg, 'X') != 'N'
         AND SYSDATE BETWEEN startdate AND  NVL(enddate, SYSDATE)
         )
    WHERE rn = 1; 
    

    Edit, currently in the trial:

    With Patient AS (
    SELECT 1  Patient_id , 'sanjay' First_name, 'kumar'  last_name FROM DUAL UNION ALL
    SELECT 2, 'ajay', 'singh' FROM DUAL UNION ALL
    SELECT 3, 'Mike', 'John' FROM DUAL),
    Address AS (
    SELECT 1   address_id, 1  patient_id, '6222'    address, 'dsadsa'   city, 'P'  type, to_date('01/01/2007', 'DD/MM/YYYY')  startdate, to_date('01/01/2010', 'DD/MM/YYYY')  enddate, NULL  valid_flg FROM DUAL UNION ALL
    SELECT 2,1,'63333','dsad','M', to_date('01/02/2006', 'DD/MM/YYYY'), to_date('01/01/2007', 'DD/MM/YYYY'),  ' N'  FROM DUAL UNION ALL
    SELECT 3,1,'64564','fdf','M', to_date('01/01/2008', 'DD/MM/YYYY'), to_date('07/01/2009', 'DD/MM/YYYY'), NULL  FROM DUAL UNION ALL
    SELECT 4,1,'654757','fsdfsa','D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'),  NULL  FROM DUAL UNION ALL
    SELECT 5,2,'fsdfsd ','fsdfsd','M', to_date('01/03/2007', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'), NULL  FROM DUAL UNION ALL
    SELECT 6,2,' jhkjk','dsad','D', to_date('01/01/2007', 'DD/MM/YYYY'), to_date('10/10/2010', 'DD/MM/YYYY'),  NULL  FROM DUAL UNION ALL
    SELECT 7,3,'asfd',' sfds',' D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('10/10/2009', 'DD/MM/YYYY'),  NULL  FROM DUAL)
    -- end test data
     SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate
     FROM (
      SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate,
                 ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1
                                                                          WHEN  'M' THEN 2
                                                                          WHEN  'D' THEN 3
                                                                        END) rn
        FROM  patient p
        JOIN  address a ON (p.patient_id = a.patient_id )
       WHERE NVL(valid_flg, 'X') != 'N'
         AND SYSDATE BETWEEN startdate AND  NVL(enddate, SYSDATE)
         )
    WHERE rn = 1; 
    
    PATIENT_ID FIRST_ LAST_ ADDRESS CITY   TY STARTDATE ENDDATE
    ---------- ------ ----- ------- ------ -- --------- ---------
             1 sanjay kumar 6222    dsadsa P  01-JAN-07 01-JAN-10
             2 ajay   singh fsdfsd  fsdfsd M  01-MAR-07 09-OCT-09
             3 Mike   John  asfd     sfds  D 01-FEB-08 10-OCT-09
    
  • Please help me fix this SQL query...

    Hi, please consider following:
    create table test (col varchar2 (255))
    insert into test values ("TERM").
    Insert test values ("VOLUME");

    Select the test pass where pass in ('TIME', 'VOLUME');
    This property returns the rows.

    but my input string is a comma-separated list:
    DURATION, VOLUME

    so I try
    Select the test pass where col to (replace (' DURATION, VOLUME, ',' "'," '));
    but no result. Or:
    Select the test pass where col in ("' | replace (' DURATION, VOLUME, ','" ', "') |") ') ;

    However
    Select "' | Replace (' DURATION, VOLUME, ',' "'," ') | " ' the double
    gives "DURATION", "VOLUME".

    then why does it work?

    hope you can help. Thank you

    convert stringlist in lines and then use in the clause...

    SELECT col
       FROM test
      WHERE col IN
      (SELECT    *
         FROM
        (SELECT TRIM( SUBSTR ( txt , INSTR (txt, ',', 1, level ) + 1 , INSTR (txt, ',', 1, level+1 ) - INSTR (txt, ',', 1, level) -1 ) ) AS token
           FROM
          ( SELECT ','||'DURATION,VOLUME'||',' AS txt FROM dual
          )
          CONNECT BY level <= LENGTH(txt)-LENGTH(REPLACE(txt,',',''))-1
        )
      )
    

    Ravi Kumar

  • The address bar where I can type in the Web addresses does not appear on my Mozilla, please help me with this... How to activate it?

    The address bar where I can type in the Web addresses does not appear on my Mozilla, please help me with this... How to activate it?

    Hi kdwis,

    Going to try view > toolbars and activation of the Bar of Navigation and in the bookmarks toolbar.

    Hope this helps!

  • When you install the 2007 Microsoft Office Suite Service Pack 2 (SP2), I still received the error code 646... I tried to download the RegCure as advised, but the problem still exists... Please help me with this problem... Thank you

    Ideas:

    • When you install the 2007 Microsoft Office Suite Service Pack 2 (SP2), I still received the error code 646... I tried to download the RegCure as advised, but the problem still exists... Please help me with this problem... Thank you

    I tried to download the RegCure as advised, but the problem still exists...

    Who advised you to 'download... '. RegCure? Doing so could only worse issues! If you ever think that your registry database must be cleaned, repaired, boosted or optimized (it isn't), read http://aumha.net/viewtopic.php?t=28099 and draw your own conclusions.

    See http://social.answers.microsoft.com/Forums/en-US/vistawu/thread/6e716883-7af4-4a9f-8665-2f4dd57eee8d ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • Hello, I have version Adobe Acrobat 11. I have complete documents and send them to customers. However, when customers open the documents on their side, they are empty. The filled information are missing. Can you please help me with this problem?

    Hello, I have version Adobe Acrobat 11. I have complete documents and send them to customers. However, when customers open the documents on their side, they are empty. The filled information are missing. Can you please help me with this problem?

    Why are publish you again? You must first answer the question I ask in your original thread.

  • BlackBerry smartphones please help me with this indicator on my screen... it has reduced the quality of the voice

    Please help me with the rectangular symbol on the top next to the speaker symbol. It seems that I turned on an option by mistake, and whenever I've make or receive a call, this symbol appears. This was not the case previously.

    For this reason, my voice call quality has declined considerably. Please help quickly.

    Thank you

    itsmits

    Of course, he was told here in the forums of many times.

    It's the Audio Boost indicator call.

    To change, press your green numbering > Menu key > Enhanced Audio Boost.

  • Please help me with this

    Hi, I'm really sorry for not posting the version of DB. and didn't you know about the scenarios of the o/p in my previous post which is linked to this.
    under query does not work because the key value 3 is missing.

    DB version: 10g

    table may or may not have continuous key values and may have up to 7 keys. Here is the example.


    with  target as (
                     select  100 profile , 1 key , 'CDE' value  from dual union all
                     select  100,2,'XXX' from dual union all
                     select  100,2,'YYY' from dual union all
                     select  100,4,'111' from dual 
                     
                    )
    select  profile || sys_connect_by_path(key || '-' || value,'/') path
      from  target t1
      where connect_by_isleaf = 1
      start with key = (select min(t2.key) from target t2 where t2.profile = t1.profile)
      connect by profile = prior profile
             and key     = prior key + 1
    o/p required:
            
    100/1-CDE/2-XXX/4-111
    100/1-CDE/2-YYY/4-111
    Published by: DeepakDevarapalli on December 11, 2009 11:21

    Hello

    This seems to be a duplicate of [this thread | http://forums.oracle.com/forums/thread.jspa?threadID=999921&tstart=0]. Please do not post to double son; He is confusing for everyone, including you and causes extra work for people who want to help you.

    One of these threads (preference, because it has no other answers) mark it as 'Response' and only use the other thread.

  • Please help me with this vi

    Hello friends I m new learner

    Please help me

    I have this program Please tell me how to send readings and data in table vi and wwhen I press the button log file it should save the file one by one? and

    Please tell me the logic also when I press next, he must go to the next page and back then return to the page and pressing out he must go out and finally next page button should disappear...

    someone help me please

    Thanks in advance

    concerning

    Naomie

    Please use complete words when entering posts on the forum and not 'text speak '.  A plea for words full

    A problem I see is that you have lots of tunnels in the structure of your case where you do not connect the data in all cases.  You end up with the tunnels for "Use default if unwired", feeding the default data in your shift register which later get used.  Probably not what you want.

  • Please help me with this &#60; I have a virus, a bug, malware or something...

    There is something called Firewall Builder windows (activate ultimate protection then asks a credit card on an anonymous line) that keeps popping up and saying I have all sorts of things wrong... but I can't find a way to remove it, it blocks my anti virus and the scanner tools Microsoft apparently can't find it I need help with this... He also does something to my to my system restore, I can't go back today... This bug also always flashes something on torrent link detected everytime I try to download something from Microsoft... it's very frustrating please help.

    sincerely of Tanya Willis

    http://www.bleepingcomputer.com/virus-removal/remove-Windows-Firewall-constructor

  • Please help me with this request - I'm trying with Dense rank

    version 10g

    I got a quote for an account. If the same quote is received under different account I should mark the old account has received as being deleted.
    Please help me.
    /* Formatted on 2010/06/28 14:13 (Formatter Plus v4.8.8) */
    WITH temp AS
         (SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
                 TO_DATE ('12/23/2009 3:37:54',
                          'mm/dd/yyyy hh:mi:ss PM'
                         ) captured_date
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'RFS',
                 TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'Rejected',
                 TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Ordered',
                 TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'RFS',
                 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Rejected',
                 TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Validated',
                 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'RFS',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'RFS',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8Z', 'COPS', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8Z', 'COPS', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL)
    SELECT   quote_id, ACCOUNT, status, captured_date,
             DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id,
              ACCOUNT) rn
    --         ,CASE DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id,
    --              ACCOUNT)
    --            WHEN 1
    --               THEN 'Y'
    --            ELSE 'N'
    --         END deleted_flag
        FROM temp
    ORDER BY quote_id, captured_date;
    power required
    WITH temp AS
         (SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
                 TO_DATE ('12/23/2009 3:37:54',
                          'mm/dd/yyyy hh:mi:ss PM'
                         ) captured_date, 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'RFS',
                 TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'Rejected',
                 TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Ordered',
                 TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'RFS',
                 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Rejected',
                 TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Validated',
                 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'RFS',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'RFS',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8Z', 'COPS', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8Z', 'COPS', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL)
    SELECT   quote_id, ACCOUNT, status, captured_date, deleted_flag
        FROM temp
    ORDER BY quote_id, captured_date;

    This gives a shot:

    SELECT quote_id
         , account
         , status
         , captured_date
         , CASE
                WHEN account_cnt  = 1
                  OR account     != first_account
                THEN 'N'
                ELSE 'Y'
           END                                     AS deleted_flag
    FROM
    (
      SELECT quote_id
           , account
           , status
           , captured_date
           , FIRST_VALUE(account) OVER (PARTITION BY quote_id ORDER BY captured_date) AS first_account
           , COUNT(DISTINCT account) OVER (PARTITION BY quote_id) AS account_cnt
      FROM   temp
    )
    ORDER BY quote_id, captured_date;
    
  • Please help me with this question...

    Hello world

    Sorry to ask the same question that has been published several times in this forum.

    I have the following scenario...
    Database name: database1
    
    schema names: schema1
                  schema2
                  schema3
                  schema4
                  schema5 
                  schema6
                  schema7
    
    workspace is with: schema1
                       schema2
    
    
    1. can i create 1 application that need to access tables in both schema1 and schema2 ?
    comments: I think we have to choose "parsing schema" when i am creating an application.
              if i choose the parsing schema as "schema1". 
    2.how can i create a "form on a table" or some other wizard based forms which is in schema2?
    3.what priviliges do i need to create "form on a table" or some other wizard based forms which is in schema2?
    
    4.As my workspace is with schema1 and schema2. How can i create "forms" on tables which are in
     schema3? do i need to "create a view of table in schema3"  in schema1?
    
    
    
    All the above question will raise if i have to create forms or reports with "wizards". Is this stmt correct?
    
    I mean if i create a form "manually" all i need to look whether i have insert,update and delete priv on
    that object? is it correct?
    I think that this question has been answered several times.sorry for the repost.

    Thank you

    It is not necessary to say "Please help me" as aid happens almost always. Maybe sometimes you need to get back your question after a while. However, back to your question. I can tell you how to solve this problem:

    grant select, insert, update, delete on all the tables in the schema of analysis
    grant select on all the analysis schema views
    grant to run on all procedures and packages to the scheme of analysis
    creation of synonyms in the scheme of analysis for all tables, views, sequences, etc.

    You can do all this programmatically in a loop instead of write for each object separatelly.

    Denes Kubicek
    ------------------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    ------------------------------------------------------------------------------

  • My computer is saying, 'you can be a victim of software counterfeiting ". Can someone please help me with this?

    My grandmother gave me her old computer a few months ago and now it says I could be victim software counterfeiting... Please help me to solve this

    Thank you

    For help, see Genuine Microsoft software web page.

  • Please help me with this procedure

    Hi guys. I am trying to create a procedure that inserts into the table of withdrawal and then print the user balance. Yet once, I created a function called get_authority that checks whether the user is allowed or not. I could write the procedure but still get an error. Please help me to correct my mistake. Thank you

    create or replace procedure (do_withdrawal)

    p_cust_id in varchar2,

    p_acc_id number,

    p_amount number

    )

    as

    v_cnr number (9);

    Exception not allowed;

    Start

    Select pk_seq.nextval in the double v_cnr;

    insert into deposits (wit_id, cust_id, acc_id, amount, Date_Time) values (v_cnr, p_cust_id, p_acc_id, p_amount, sysdate);

    commit;

    EXCEPTION

    Where (get_authority = 0 ;) then)

    Unauthorized, Sunrise

    dbms_output.put_line ("'User Unauthrorized")

    on the other

    dbms_output.put_line (' Dear customer: your balance is ')

    end;

    Yes, you can

    create or replace procedure do_withdrawal

    (

    p_cust_id in varchar2,

    p_acc_id number,

    p_amount number

    )

    as

    exception unathurozied;

    Start

    If get_authority = 0 then

    raise unathurozied;

    on the other

    Insert in deposits

    (

    wit_id,

    cust_id,

    acc_id,

    amount,

    Date_Time

    )

    values

    (

    pk_seq.nextval,

    p_cust_id,

    p_acc_id,

    p_amount,

    SYSDATE

    );

    end if;

    exception

    When unathurozied then

    raise_application_error (-20010, "Unathorized user");

    end;

  • Please help me with this query

    Hello
    I try to use an OR condition in NOT IN clause, the SQL statement correct way:

    Select the name of master_list where ((id not in (select id from deleted_list)) OR (id not in (select id from inactive_list)))

    I have two tables that contain identifiers that should not be in the paragraph.

    Thank you
    Raja

    How about this?

    select name from master_list where
         id not in (
              select id from deleted_list
              union
              select id from inactive_list
              )
    

    Arun-

    Not tested

Maybe you are looking for

  • Firefox 24 plant

    Comment by a moderator of the forum. Anyone with the Norton software Please also see these messages by CheckMate below in this thread: [/questions/971603 #answer - 483017] [/questions/971603? page = 2 #answer-485265] I updated to Firefox 24.0 today (

  • Problem installing NOR-488. 2 for windows 7

    Facing some installation issues that need your support. Tried to install NOR-488. 2 for windows 7 and there is a window pop up. See attachment. CAN advice there at - it a patch of window to fix this? Thank you Mike.T

  • After the launch and the release of Cisco close Windows loses the functionality of micro.

    If I run the Cisco close Windows application, I lose the microphone feature. I understand from the client accesses the pair with the SX camera microphone. But if I left out the functionality of client micro does not. I need to restart my computer for

  • BlackBerry Z10 BB link and a printer Canon (not wireless)

    I could always print Web page statements and MS Word documents from my laptop to my printer via a cable. After you download BlackBerry link I can no longer print documents because a small BlackBerry window opens asking to connect wireless to my BB ID

  • Where will the files deleted in windows xp mode 7?

    As the title suggests, where deleted in XP mode files go to? I deleted a file on my local C drive using the XP mode. The file did not go to the XP virtual recycling bin or windows 7 recycling bin.  The file was small and did not warn me that it does