SQL Query to find missed nunmber from each group

Hi,
I have a set of records called "Level" and its values are A, B, C, D.
From the below list, I want to identify the missed level for each group.
ID          Level          Type
1             A               Floor
1             B                Floor
2             A               Wind           
2             C                Wind
I need result like: [Missed level records]
ID          Level          Type
1               C             NULL     1- doesnt has C and D
1               D             NULL
2               B             NULL      2- doesnt has A and C
2               D             NULL
Pls suggest.
Regards,
-Sugumar Pannerselvam

Hi,
Got output with below code. may helpful for others.
DECLARE @TblLevel TABLE(Level VARCHAR(10))
INSERT INTO @TblLevel(Level) VALUES('A'),('B'),('C'),('D')
DECLARE @TblRecords TABLE(ID INT, Level CHAR(1), Type VARCHAR(10))
INSERT INTO @TblRecords(ID, Level, Type) VALUES(1,'A','Floor'),(1,'B','Floor'),(2,'A','Wind'),(2,'C','Wind')
DECLARE @TblResult TABLE(ID INT, Level CHAR(1), Type VARCHAR(10))
INSERT INTO @TblResult(ID, Level, Type)
SELECT DISTINCT ID, TblLevel.Level, Type
FROM @TblRecords TblRec
CROSS JOIN @TblLevel TblLevel
SELECT TblResult.* FROM @TblResult TblResult
LEFT OUTER JOIN @TblRecords TblRec ON TblResult.ID = TblRec.ID AND TblResult.Level = TblRec.Level
WHERE TblRec.Level IS NULL
ORDER BY 1
Looking for some best way to achieve this. As of now considered this as answer. :-)
Regards,
Sugumar Pannerselvam.

Similar Messages

  • SQL Query for getting Row No for each group

    Dear Oracle Gurus,
    I want to allocate Rownum to each group. How we can do this with single SQL. Help me on this.
    Thanks

    select deptno, ename, row_number() over (partition by deptno order by ename) from emp order by 1,3;

  • Sql query to find the balances for a customer account wise.

    Hi,
    Could someone help me with the sql query to find the balances for each customer account wise. This is need to generate the report.
    presently we are using this query, but the output doesnot return the expected result.
    SELECT sum(nvl(ps.acctd_amount_due_remaining,0)) "Balance"
    FROM      ra_cust_trx_line_gl_dist_all gld,
              gl_code_combinations c,
              ar_payment_schedules_all ps,
              RA_CUSTOMER_TRX_ALL rat,
              ra_customers rc
    WHERE      c.CHART_OF_ACCOUNTS_ID = 101
    and gld.code_combination_id = c.code_combination_id
         and rat.CUSTOMER_TRX_ID=gld.CUSTOMER_TRX_ID
         and rat.CUSTOMER_TRX_ID=ps.CUSTOMER_TRX_ID
    and ps.customer_id=rc.customer_id
         and ps.status='OP'
         and ps.gl_date <= :PDATE
         and ps.org_id=:PORGID
         and ps.class in ('GUAR','INV','DM','DEP')
    and c.SEGMENT4=:Account_id
    and ps.customer_id=:Customer_id
    Thanks in advance.
    Kalyan.

    Can someone help us with this.

  • SQL Query to find menus and submenus attached to responsibility

    Hi,
    I am looking for help to find out a sql query to pull out the list of all the menu's associated with each of the responsibilities assigned to users. Please let me know any SQL query to find out menus attached for responsibilities assigned to users.

    835129 wrote:
    I was asked by my lead to list out responsibilities and attached menus and I was asked to submit the output from production. In the metalink note provided by you it was asked to create table collecting all menu id's and I cannot create any tables in production. Apart from this there were 1000's of users with different responsibilities and different menus. I cannot collect all of the users menu ids.
    I just want to list out responsibilities and attached menus. Is that something you can helpout withhttps://forums.oracle.com/forums/search.jspa?threadID=&q=fnd_responsibility_vl+AND+fnd_menu&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    https://forums.oracle.com/forums/search.jspa?threadID=&q=fnd_responsibility_tl+AND+FND_MENU_ENTRIES_TL&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Please search the forum for these tables/views and you should get many hits:
    FND_MENU_ENTRIES_TL
    FND_MENU_ENTRIES_VL
    FND_RESPONSIBILITY_TL
    FND_RESPONSIBILITY_VL
    Thanks,
    Hussein

  • Sql query to find answered and received calls for month or day

    Hi  experts !
    1.Any one help in finding out the received, answered and missed ,transfered  in  /  out  calls  in  UCCE  using SQL query for a particular month or day.
    2. We have some  custom report templetes defined ,  need to  know  , how can we  write Sql  query  to  get those  values  from  custum reports.
    due to some issues,  cannot use  webview .

    Hi,
    there's no such thing as reporting "for a particular Team". Teams in ICM are for administration purposes only (to have grouping of agents). ICM does not count the number of calls received by "teams". If there is a report in Webview "by team", it's always by agent. Try to run the report against a team once and then try to remove certain agents from that team - you'll see the difference.
    What you are looking for is either reporting by Agent or by Agent/Skill group combination.
    Try to explore the
    - Agent_Half_Hour
    - Agent_Skill_Group_Half_Hour
    - Skill_Group_Half_Hour
    database views.
    The database schema documents are here:
    http://www.cisco.com/en/US/products/sw/custcosw/ps1844/prod_technical_reference_list.html
    Good luck.
    G.

  • Can anybody provide the SQL query to find the files uploaded in a particular folder?

    Hi All,
    Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
    GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
    Any help is greatly appreciated.
    With best regards,
    Nevin

    Nevin,
    Be great if we could know the version of Portal. For Rel. 1, here's the query
    select id,masterthingid from wwv_things
    where siteid = &site
    and cornerid = &corner
    &site - Content Area id
    &corner - Folder id
    if you don't know the folder id, use
    select id from wwv_corners where siteid = &site
    and name = &folder
    Hope this helps. I have run into this situation before. Usually, the culprits were
    one of the following:
    1. Junk Characters in description of item (caused due to Copy-Paste)
    2. Special Characters in the File name
    Hi All,
    Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
    GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
    Any help is greatly appreciated.
    With best regards,
    Nevin

  • SQl query to find incompatibility defined

    If two programs are defined as incompatible with one another, the data these programs cannot access simultaneously must also be identified.
    This can be found from concurrent program->define from front end ebs login, but is there any SQL query to find this for a particular program or request set??
    Thanks in advance.

    Please search the forum before posting similar questions.
    Concurrent-Conflict
    Re: Concurrent-Conflict
    Thanks,
    Hussein

  • SQL Query to find DN and phone Load

    Hi All,
    We are using Call Manager 8.6 [one PUB and 4 SUBs] and have different IP phone models .
    IP phone model have different LOAD working with them like few 3905 have cmterm-3905.9-2-2-0 while some have cmterm-3905.9-2-2ES7 .
    Is there any way/SQL Query  to find out what all phone model with DN are running 3905.9-2-2.0 LOAD?
    regds,
    aman

    Hey Aman,
    Hope all is well my friend!
    Just to add a note to my friend Carlo's good info here (+5!)
    Try;
    Device> Device Settings> Firmware Load Information>Device Not Using Default Load
    This will show you any phones that deviate from the "device defaults" Fimware And if you click
    on any device listed here it will show the actual Firmware that is being used on the specified device.
    Cheers!
    Rob

  • SQL Query to Find out User has what all resources provisioned !

    Hi Guys ,
    Does any one have a SQL query to find out what resources are provisioned to a particular user ?
    Thanks
    Suren

    Hi,
    Hope this will help you.
    SELECT distinct usr_login as "IdM User ID",
    usr_employeeID as "Employee ID",
    usr.USR_FIRST_NAME as "First Name",
    usr.USR_LAST_NAME as "Last Name",
    usr_status
    as "User Status",
    USR_EMP_TYPE as "Employee Type",
    obj.obj_name as "Application Resource",
    ost_status as "Application Resource Status",
    FROM ost,oiu,obj,usr,obi
    WHERE oiu.ost_key = ost.ost_key AND obj.obj_key = obi.obj_key AND oiu.usr_key = usr.usr_key
    AND ost_status in ('Provisioned','Revoked','Disabled', 'Provisioning')
    AND oiu.obi_key=obi.obi_key
    AND usr_EmployeeID like '11111'
    This query will provide all the resources to which the user is linked with and the resource status is in 'Provisioned','Revoked','Disabled', 'Provisioning' status for a particular employeed ID, I am not completely sure whether I have given the Employee ID column from USR table as correct or not. Verify once and query the DB

  • Write the sql query to find largest value in row wise without using   great

    write the sql query to find largest value in row wise without using
    greatest fuction?

    Another not so good way, considering you want greatest of 4 fields from a single record:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (Select 100 col1,200 col2,300 col3,400 col4 from dual
      2  union select 500,600,700,800 from dual
      3  union select 900,1000,1100,1200 from dual
      4  union select 1300,1400,1500,1600 from dual
      5  union select 1700,1800,1900,2000 from dual
      6  union select 2100,2200,2300,2400 from dual
      7  union select 2800,2700,2600,2500 from dual
      8  union select 2900,3000,3100,3200 from dual)
      9  SELECT (CASE WHEN col1 > col2 THEN col1 ELSE col2 END) Max_value
    10  FROM
    11  (SELECT (CASE WHEN col1_col2 > col2_col3 THEN col1_col2 ELSE col2_col3 END) col1,
    12         (CASE WHEN col2_col3 > col3_col4 THEN col2_col3 ELSE col3_col4 END) col2,
    13         (CASE WHEN col3_col4 > col4_col1 THEN col3_col4 ELSE col4_col1 END) col3
    14  FROM
    15  (SELECT (CASE WHEN col1 > col2 THEN col1 ELSE col2 END) col1_col2,
    16         (CASE WHEN col2 > col3 THEN col2 ELSE col3 END) col2_col3,
    17         (CASE WHEN col3 > col4 THEN col3 ELSE col4 END) col3_col4,
    18         (CASE WHEN col4 > col1 THEN col4 ELSE col1 END) col4_col1
    19* FROM t))
    SQL> /
    MAX_VALUE
           400
           800
          1200
          1600
          2000
          2400
          2800
          3200
    8 rows selected.
    SQL> Edited by: AP on Sep 21, 2010 6:29 AM

  • Sql query to find all contacts for an account

    I wonder if someone wrote an sql query to find all contacts for an account number in Oracle customer master. We are on EBS 11.5.10.
    I am also looking for sql query to find all ship to addresses for an account number.
    Thanks.

    Can you also post the query for people who read this post and are also looking for an answer?
    Regards,
    Johan Louwers.

  • SQL query to find sqlnet.ora parameters

    Hi All,
    I am working 11g RAC /solaris 9
    I want have sql query to find values of sqlnet.ora parameters
    May be values of SQLNET.INBOUND_CONNECT_TIMEOUT
    SQLNET.SEND_TIMEOUT, SQLNET.RECV_TIMEOUT
    Thanks
    raj

    The sqlnet.ora file is the profile configuration file. It resides on the client machines and the database server.
    Profiles are stored and implemented using this file. The database server can be configured with access control parameters in the sqlnet.ora file.
    These parameters specify whether clients are allowed or denied access based on the protocol.
    The sqlnet.ora file enables you to do the following:
    Specify the client domain to append to unqualified names
    Prioritize naming methods
    Enable logging and tracing features
    Route connections through specific processes
    Configure parameters for external naming
    Configure Oracle Advanced Security
    Use protocol-specific parameters to restrict access to the database
    By default, the sqlnet.ora file is located in the ORACLE_HOME/network/admin directory. The sqlnet.ora file can also be stored in the directory specified by the TNS_ADMIN environment variable.
    You can not query on this file sqlnet.ora as tnsnames.ora file.
    Regards
    Mahir M. Quluzade

  • SQL query to find access database files?

    Odd request, but does anyone have a SQL query to find files? Specifically, I am looking for machines that have access databases on them. .mdb & .accdb

    Have you enabled inventory for them?
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ
    i was trying to figure out where that option was but couldn't find it under hierarchy settings. perhaps it's been changed since 2012 R2? can you help point it out?

  • SQL to group the records and apply logic to pick one record from each group

    Hi Friends,
    I am looking for a query to group the records on certain columns in a table and then from each group I want to pick only one record based on certain rules.
    May be having data laid out will make my point more clear to you. Here you go :
    CREATE TABLE AD_LIST
      FILE_NAME             VARCHAR2(50 BYTE),
      ACTIVITY_START        DATE,
      ACTIVITY_END          DATE,
      DIVISION              VARCHAR2(50 BYTE),
      ITEM_CODE             VARCHAR2(50 BYTE),
      MULT                  NUMBER,
      RETAIL                NUMBER,
      AD_PAGE               VARCHAR2(1 BYTE),
      FORECAST              NUMBER,
      MEMO                  VARCHAR2(50 BYTE)
    INSERT INTO AD_LIST VALUES ('FILE_1','01-APR-2010','15-APR-2010','B',1111,5,10,'A',10,'This must be in my result');
    INSERT INTO AD_LIST VALUES ('FILE_1','01-APR-2010','15-APR-2010','B',1111,1,1,'B',15,'Must not be in my result');
    INSERT INTO AD_LIST VALUES ('FILE_1','01-APR-2010','15-APR-2010','B',1111,6,15,'C',11,'Must not be in my result');
    INSERT INTO AD_LIST VALUES ('FILE_1','16-APR-2010','30-APR-2010','N',1111,4,20,'D',40,'Must not be in my result');
    INSERT INTO AD_LIST VALUES ('FILE_1','16-APR-2010','30-APR-2010','N',1111,5,15,'E',30,'Must not be in my result');
    INSERT INTO AD_LIST VALUES ('FILE_1','16-APR-2010','30-APR-2010','N',1111,1,2,'F',20,'This must be in my result');
    CREATE TABLE PAGE_RANK
      AD_PAGE VARCHAR2(1 BYTE),
      RANK NUMBER
    INSERT INTO PAGE_RANK VALUES ('A',1);
    INSERT INTO PAGE_RANK VALUES ('B',2);
    INSERT INTO PAGE_RANK VALUES ('C',3);
    INSERT INTO PAGE_RANK VALUES ('D',4);
    INSERT INTO PAGE_RANK VALUES ('E',5);
    INSERT INTO PAGE_RANK VALUES ('F',6);
    COMMIT;
    SELECT * FROM AD_LIST
    FILE     ACTIVITY     ACTIVITY          ITEM               AD
    NAME     START          END          DIV     CODE     MULT     RETAIL     PAGE     FORECAST     MEMO
    FILE_1     4/1/2010     4/15/2010     B     1111     5     10     A     10     This must be in my result
    FILE_1     4/1/2010     4/15/2010     B     1111     1     1     B     15     Must not be in my result
    FILE_1     4/1/2010     4/15/2010     B     1111     6     15     C     11     Must not be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     4     20     D     40     Must not be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     5     15     E     30     Must not be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     1     2     F     20     This must be in my resultNow, from the table AD_LIST I want to group the records based on FILE_NAME, ACTIVITY_START, ACTIVITY_END, DIVISION, ITEM_CODE.
    So in my example here we have 2 set of records grouped based on the columns specified.
    Also we have one more table, PAGE_RANK, which has a rank corresponding to each ad_page number. Here 1 is higher rank than 2. Hence ad page 'A' takes priority over 'B'. Similarly for all other ad pages.
    Now, we need to pick one ad from each group of ads by determining the highest ranked ad page within the group and the value for mult and retail must be replaced with the value that has min(retail/mult). So, using the above data we will have the one having ad page = 'A' and ad page = 'D' as the final results since they have highest ad page rank in their group.
    The value for mult and retail values for ad_page 'A' = min (10/5 , 1/1, 15/6) = 1,1(mult,retail).
    The value for mult and retail values for ad_page 'D' = min (20/4 , 15/5, 2/1) = 1,2(mult,retail).
    Finally I have this query below
    SELECT a.file_name,
           a.activity_start,
           a.activity_end,
           a.division,
           a.item_code,
           FIRST_VALUE (a.mult) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (a.retail /
                                                                                                                                    a.mult))
                                                                                                        mult,
           FIRST_VALUE (a.retail) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (a.retail /
                                                                                                                                      a.mult))
                                                                                                      retail,
           FIRST_VALUE (a.ad_page) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (b.RANK))
                                                                                                     ad_page,
           a.forecast,
           a.memo                                                                                                
      FROM ad_list a, page_rank b
    WHERE a.ad_page = b.ad_pageThis query is giving me all the records but with the values what I wanted in Ad_Page, Mult and Retail columns.
    How can I pick only one from each group.
    I am getting this FILE     ACTIVITY     ACTIVITY          ITEM               AD
    NAME     START          END          DIV     CODE     MULT     RETAIL     PAGE     FORECAST     MEMO
    FILE_1     4/1/2010     4/15/2010     B     1111     1     1     A     15     Must not be in my result
    FILE_1     4/1/2010     4/15/2010     B     1111     1     1     A     10     This must be in my result
    FILE_1     4/1/2010     4/15/2010     B     1111     1     1     A     11     Must not be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     1     2     D     20     This must be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     1     2     D     30     Must not be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     1     2     D     40     Must not be in my resultBut I want this FILE     ACTIVITY     ACTIVITY          ITEM               AD
    NAME     START          END          DIV     CODE     MULT     RETAIL     PAGE     FORECAST     MEMO
    FILE_1     4/1/2010     4/15/2010     B     1111     1     1     A     10     This must be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     1     2     D     20     This must be in my resultI have to run this query for thousands of such group combination.
    Hope some one can throw some light on this query.
    Thanks in advance,
    Raj.

    Frank,
    You are marvelous.
    That is what I was expecting, but basically I want to display the row with highest page rank which is 'A' and 'D' in this case.
    So I have changed my query as below using yours :
    WITH mainq AS
         (SELECT a.file_name,
                 a.activity_start,
                 a.activity_end,
                 a.division,
                 a.item_code,
                 FIRST_VALUE (a.mult) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (a.retail /
                                                                                                                                          a.mult))
                                                                                                        mult,
                 FIRST_VALUE (a.retail) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (a.retail /
                                                                                                                                            a.mult))
                                                                                                      retail,
                 --FIRST_VALUE (a.ad_page) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (b.RANK))
                 a.ad_page,
                 a.forecast,
                 a.memo,
                 ROW_NUMBER () OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY b.RANK)
                                                                                                 AS r_num
            FROM ad_list a, page_rank b
           WHERE a.ad_page = b.ad_page)
    SELECT *
      FROM mainq a
    WHERE r_num = 1
    FILE     ACTIVITY     ACTIVITY          ITEM               AD
    NAME     START          END          DIV     CODE     MULT     RETAIL     PAGE     FORECAST     MEMO
    FILE_1     4/1/2010     4/15/2010     B     1111     1     1     A     10     This must be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     1     2     D     40     Must not be in my resultMy apologies that I gave you wrong forecast and memo values in my earlier post.
    But that is what I wanted and your input greatly helped me to save lot of time by using in one single query.
    Earlier I was using cursor to do that and it was not doing any good performance wise.
    Thanks to every body for your time and your efforts.
    I appreciate it.
    Have fun.
    ~Raj

  • SQL query to find out last login for each database

    Hi everybody,
    I have a view with following columns:
    DatabaseSid, lastLogin, firstLogin.
    I want to now the newest last_login date for every database.
    SID First Login Last Login
    e.g. Database1, 11.11.2011, 01.12.2011
    Database1, 01.04.2012, 01.05.2012
    Database3, 03.03.2004, 03.06.2005
    Database 3 07.09.2012, 12.10.2012
    How can I do a query to find out for eacht DB (DB1, DB2 and so on) the Last_Login Date?
    Thank you in advance
    Steve

    Steve wrote:
    Hi everybody,
    I have a view with following columns:
    DatabaseSid, lastLogin, firstLogin.
    I want to now the newest last_login date for every database.
    SID First Login Last Login
    e.g. Database1, 11.11.2011, 01.12.2011
    Database1, 01.04.2012, 01.05.2012
    Database3, 03.03.2004, 03.06.2005
    Database 3 07.09.2012, 12.10.2012
    How can I do a query to find out for eacht DB (DB1, DB2 and so on) the Last_Login Date?
    Thank you in advance
    SteveI'm curious as to how you collect this information from multiple databases into one database, and of what value the data is once you have it.

Maybe you are looking for

  • Apple Micro-DVI to Video Adapter New MacBook Air

    Hi All, I am brand new to the Mac world (Been a PC user my entire life). Thought I would take a gamble on a Mac and see how it goes. So far I have been really impressed and happy! I bought a MacBook Air a few weeks ago. It's a 2.13 GHZ MacBook Air. I

  • Printing to shared windows printer over wireless network

    Hi, I just bought my wife a MacBook and recently updated it to Leopard (OS X 10.5). I have a Lexmark X5150 printer connected to a desktop PC running Windows XP. I can share files between the two computers no problem either wirelessly or through an et

  • My ipod touch is stuck on the usb to itunes and itunes wont restore my ipod. Help?

    My Ipod touch, 4g i think, is stuck on the USB to Itunes and when i connect it to itunes it says that i cant use it untill i restore it. So i clicked on Restore and update. It goes untill the bar at the top is fully filled then a message pops up sayi

  • Pages reformats Word documents

    I'm going to be purchasing a new MacBook Pro in the next few weeks, so I stopped by the Apple Store at The Grove to check whether Pages reformats Word .docs.  Upon importing one of my three archaeological research papers, which consist of text and hu

  • Platform Migration During EBS upgrade

    Hi , We are planing to upgrade oracle apps from 11.5.10.2 to R12.1.3. Currently Both oracle apps(11i) and DB(11gR1) are on IBM-AIX 5.3. also planing for OS migration from AIX 5.3 to Linux x86-64. So what would be the better option : 1. Migrate existi