Cant get this simple query!

Hi Guys,
There is this simple requirement of writing a query which will select most of the columns from a table but grouped on 3 columns from same table.
Table Str:
co11 col2 col3 col4 col5 col6 col7 col8 col9 col10
Required :
Group By: Col9, col10
Columns to be selected : co11 col2 col3 col4 col5 col6 col7 col8
I know there is something simple that I am missing.
any help will be appreciated.
Thanks!

Hi,
This produces the output you requested fro the data you posted:
SELECT       MIN (col1)
,       MIN (col2)
,       MIN (col3)
,       MIN (col4)
,       MIN (col5)
,       MIN (col6)
,       MIN (col7)
,       MIN (col8)
,       col9
,       col10
FROM       str
GROUP BY  col9
,       col10
;So does this
WITH     got_rnum     AS
     SELECT  str.*
     ,     ROW_NUMBER () OVER ( PARTITION BY  col9
                         ,             col10
                         ORDER BY        col1
                         ,             col2
                         ,             col3
                         ,             col4
                         ,             col5
                         ,             col6
                         ,             col7
                         ,             col8
                         )     AS rnum
     FROM     str
SELECT     col1
,     col2
,     col3
,     col4
,     col5
,     col6
,     col7
,     col8
,     col9
,     col10
FROM     got_rnum
WHERE     rnum     = 1
;With the sample data you posted, the two queries produce the same results.
With some other data, the two queries will produce different results.

Similar Messages

  • Trying to optimize this simple query

    Hi,
    I am trying to optimize this simple query but the two methods I am trying actually make things worse.
    The original query is:
    SELECT customer_number, customer_name
    FROM bsc_pdt_account_mv
    where rownum <= 100
    AND Upper(customer_name) like '%SP%'
    AND customer_id IN
    SELECT cust_id FROM bsc_pdt_assoc_sales_force_mv
    WHERE area_identifier IN (
    SELECT area_identifier FROM bsc_pdt_assoc_sales_force_mv
    WHERE ad_identifier = '90004918' or rm_identifier = '90004918' or tm_identifier = '90004918'
    The result set of this query returns me the first 100 rows in 88 seconds and they are all distinct by default (don't know why they are distinct).
    My first attempt was to try to use table joins instead of the IN conditions:
    SELECT
    distinct -- A: I need to use distinct now
    customer_number, customer_name
    FROM bsc_pdt_account_mv pdt,
    bsc_pdt_assoc_sales_force_mv asf,
    SELECT distinct area_identifier FROM bsc_pdt_assoc_sales_force_mv
    WHERE ad_identifier = '90004918' or rm_identifier = '90004918' or tm_identifier = '90004918'
    ) area
    where
    area.area_identifier = asf.area_identifier
    AND asf.cust_id = pdt.customer_id
    AND Upper(customer_name) like '%SP%'
    AND rownum <= 100 -- B: strange when I comment this out
    order by 1
    I dont understand two things with this query. First issue, I now need to put in the distinct because the result set is not distinct by default. Second issue (very strange), when I put the rownum condition (<100) I get two rows in 1.5 seconds. If I remove the condition, I get 354 rows (whole result set) in 326 seconds.
    My second attempt was to use EXISTS instead of IN:
    SELECT
    customer_number, customer_name
    FROM bsc_pdt_account_mv pdt
    where Upper(customer_name) like '%SP%'
    AND rownum <= 100
    AND EXISTS
    select 1 from
    bsc_pdt_assoc_sales_force_mv asf,
    SELECT distinct area_identifier FROM bsc_pdt_assoc_sales_force_mv
    WHERE ad_identifier = '90004918' or rm_identifier = '90004918' or tm_identifier = '90004918'
    ) area
    where
    area.area_identifier = asf.area_identifier
    AND asf.cust_id = pdt.customer_id
    This query returns a similar distinct result set as teh original one but takes pretty much the same time (87 seconds).

    The query below hangs when run in TOAD or PL/SQL Dev. I noticed there is no rows returned from the inner table for this condition.
    SELECT customer_number, customer_name
    FROM
    bsc_pdt_account_mv pdt_account
    where rownum <= 100
    AND exists (
    SELECT pdt_sales_force.cust_id
    FROM bsc_pdt_assoc_sales_force_mv pdt_sales_force
    WHERE pdt_account.customer_id = pdt_sales_force.cust_id
    AND (pdt_sales_force.rm_identifier = '90007761' or pdt_sales_force.tm_identifier = '90007761') )
    ORDER BY customer_name
    -- No rows returned by this query
    SELECT pdt_sales_force.cust_id
    FROM bsc_pdt_assoc_sales_force_mv pdt_sales_force
    WHERE pdt_sales_force.rm_identifier = '90007761' or pdt_sales_force.tm_identifier = '90007761'

  • I don't understand why a person who has been with a company for 6 years cant get a simple upgrade can anyone help figure that out?

    I don't understand why a person who has been with a company for 6 years cant get a simple upgrade can anyone help figure that out?

    Are you trying to get an upgrade before you're actually eligible? If that is the case, it doesn't matter if you've been a customer for 6 years or 6 days...if you're not eligible then you're not eligible. Some of your possible options are to pay full retail, do an early edge up (if you are eligible for that option), or buying a phone from some other source to use.
    If your situation is something different then it might help to share that. The options may still be the same but it helps to know what exactly the issue is.

  • This simple query takes 2 hrs. How to improve it??

    This is a simple query. It takes 2 hours to run this query. Tables have over 100,000 rows.
    SELECT
      TO_CHAR(BC_T_ARRIVALS.ARR_FLIGHT_DATE,'DD/MM/YYYY') ARR_FLIGHT_DATE
    FROM
      BC_T_ARRIVALS a,  BC_M_FLIGHTS f
    WHERE
      a.ARR_FLT_SEQ_NO = f.FLT_SEQ_NO AND
      f.FLT_LOC_CODE       = PK_BC_R_LOCATIONS.FN_SEL_LOC_CODE('BANDARANAYAKE INTERNATIONAL AIRPORT')  AND TO_CHAR(a.ARR_FLIGHT_DATE,'YYYY/MM/DD') >= TO_CHAR(:P_FROM_DATE,'YYYY/MM/DD')
    AND TO_CHAR(a.ARR_FLIGHT_DATE,'YYYY/MM/DD') <= TO_CHAR(:P_TO_DATE,'YYYY/MM/DD')
    UNION
    SELECT
      TO_CHAR(BC_T_DEPARTURES.DEP_FLIGHT_DATE,'DD/MM/YYYY') DEP_FLIGHT_DATE
    FROM
      BC_T_DEPARTURES d, BC_M_FLIGHTS f
    WHERE
      d.DEP_FLT_SEQ_NO = BC_M_FLIGHTS.FLT_SEQ_NO  AND
      f.FLT_LOC_CODE = PK_BC_R_LOCATIONS.FN_SEL_LOC_CODE('BANDARANAYAKE INTERNATIONAL AIRPORT')  AND TO_CHAR(d.DEP_FLIGHT_DATE,'YYYY/MM/DD') >= TO_CHAR(:P_FROM_DATE,'YYYY/MM/DD')
    AND TO_CHAR(d.DEP_FLIGHT_DATE,'YYYY/MM/DD') <= TO_CHAR(:P_TO_DATE,'YYYY/MM/DD')As I see it, this query will not make the DB engine use any indexes since expressions are used in the 'WHERE' clause. Am I correct?
    How can we improve the performance of this query???

    Maybe (do you really need to convert dates to chars ? That might prevent index use ...)
    select f.BC_M_FLIGHTS,
           TO_CHAR(BC_T_DEPARTURES.DEP_FLIGHT_DATE,'DD/MM/YYYY') DEP_FLIGHT_DATE,
           TO_CHAR(BC_T_ARRIVALS.ARR_FLIGHT_DATE,'DD/MM/YYYY') ARR_FLIGHT_DATE
      from (select BC_M_FLIGHTS,
                   FLT_LOC_CODE
              from BC_M_FLIGHTS
             where FLT_LOC_CODE = PK_BC_R_LOCATIONS.FN_SEL_LOC_CODE('BANDARANAYAKE INTERNATIONAL AIRPORT')
           ) f,
           BC_T_ARRIVALS a,
           BC_T_DEPARTURES d
    where f.BC_M_FLIGHTS = a.ARR_FLT_SEQ_NO
       and f.BC_M_FLIGHTS = d.DEP_FLT_SEQ_NO
       and (TO_CHAR(a.ARR_FLIGHT_DATE,'YYYY/MM/DD') between TO_CHAR(:P_FROM_DATE,'YYYY/MM/DD') and TO_CHAR(:P_TO_DATE,'YYYY/MM/DD')
        or  TO_CHAR(d.DEP_FLIGHT_DATE,'YYYY/MM/DD') between TO_CHAR(:P_FROM_DATE,'YYYY/MM/DD') and TO_CHAR(:P_TO_DATE,'YYYY/MM/DD')
           )Regards
    Etbin
    Edited by: Etbin on 2.3.2012 18:44
    select column list altered

  • I just cant get this iPod to sync my iPhoto library

    Hey, I am getting kinda frustrated here...I am able to sync my music and so on, but when I try to sync my iphoto library I get ( THIS IPOD CANNOT BE SYNCED, REQUIRED FILES CANNOT BE FOUND ) ..
    mind you, when I sync photo's from my picture album, everything shows up from there ..So why isnt my iphoto library syncing ?it's itunes and iphoto and a ^%$#@& ipod! why doesnt it work?
    Please help me cause I tried everything and apple doesnt even give me a half fast answer ....
    all they tel me is well we have had a few people call with the same issue and I asked , so what did you tell them, and I get nonsense, they just decided to work on it cause there's no apple store in their neck of the woods !
    I need help !
    it's an 80 gb ipod and Im on a intel based mac running leopard .all my software is up to date..evrything is as it should be .EXCEPT FOR MY IPOD !

    Okay guy's, I figured out whats wrong and I worked down the line and found that if I just synced folder by folder, one by one ..I would see where it's going wrong.
    and I did, Some of the photo s I have in iPhotoin those particular events were edited in different apps and so on. several times I estimated ..
    So in short, if any of you guy's remember editing your photo's over and again , it just screws up the metadata and doesnt allow it to be reconized after imported into iPhoto.
    so I found all my original pics and not the ones in the iphoto library but the ones I have stored in an external camera drive, and reimported them into iPhoto and then edited as much as I wanted and it workes just fine now..
    I hope this helps and I hope I didnt sound to much like I was rambling on.
    Thanks for your answers to ...

  • How do you get the personas to work when you scroll the pointer over it? i cant get this to work. i have to wear it just to see how it looks

    when you mouse over the persona it should wear it so you see how
    it looks. my wont do anything. i have to wear it to see if i like it and
    if not then i have to remove it. is there something i need to enable
    to get this to work. im using firefox 4 with windows xp.

    Previewing a persona only works on sites that are white-listed via an allow exception.
    You can see the permissions for the domain in the current tab in:
    * Tools > Page Info > Permissions > [X] Install Extensions or Themes
    * Tools > Options > Security : "Warn me when sites try to install add-ons": Exceptions
    Make sure that you do not use [[Clear Recent History]] to clear the 'Site Preferences'.
    See http://kb.mozillazine.org/Themes#Lightweight_theme

  • What is wrong with this simple query

    Hi,
    I am writting a simple code just to get the maximum no values from a database table
    The query is
    ResultSet = stm.executeQuery("SELECT MAX(column_name) FROM Database_table ");
    it seems to be a simple one but i am getting the message
    column not found
    Please answer soon

    Well, it depends on how your resultset is retrieving the results. If you retrieve by column name, then that's your problem. You need to do something like this:
    ResultSet = stm.executeQuery("SELECT MAX(column_name) AS myColumnName FROM Database_table ");
    String myResult = ResultSet.getString(myColumnName);Using MAX, COUNT, etc, will return your result with a mangled or no actual column name to retrieve from. Optionally, you can solve your problem by:
    ResultSet.getString(1);Michael Bishop

  • How to get this sql query value in oracle query?

    Hi all,
    i am using one query in sql that is
    select @EarlyLeaversMin = DATEDIFF(Minute,@OutTime,@nshiftmax)
    suppose first line query is getting 60 minutes.
    select @EarlyLeaversMin1=DATEDIFF(Minute,@temphrs,@ShiftTime)
    second line query is also getting 60 minutes
    set @EarlyLeaversMin=@EarlyLeaversMin+@EarlyLeaversMin1+1
    and now here it's calculating both variable minutes and storing in @earlyleaversmin that should store like 60+60+1=121 mintes
    select @EarlyLeaverstimeformat = CONVERT(char(8),Dateadd(n,@EarlyLeaversMin,0),108)
    so now it will store in this query that value in this format : 01:21:00
    can i use the same which it's happening here??
    thanks

    Oracle handles dates and time very differently from SQL Server (as I gather others on this forum have already tried to explain to you).
    Anyway, Oracle does not have a TIME datetype, but what it does have are INTERVALs. In this case you would use INTERVAL DAY TO SECOND. It's not completely clear what you mean by "store in this query that value" but we can use INTERVALS as both table columns and PL/SQL variables.
    So your first query would be something like this:
    declare
        interval_var  INTERVAL DAY TO SECOND;
    begin
         select (nshiftmax - outtime) day to second
         into interval_var
         from whatever;We can do arithmetic with interval variables.
         select (nshiftmax - outtime) day to second +  (shifttime - temphrs) day to second
         into interval_var
         from whatever;To add a hard-coded interval such as 1 minute you can use this functionality:
         interval_var := interval_var + to_dsinterval('0 0:1:0');There's loads of info in the Oracle documentation. [url http://docs.oracle.com/cd/B28359_01/server.111/b28286/sql_elements001.htm#sthref115]Find out more.
    Cheers, APC

  • Why is this simple query failing?

    Select T0.[docentry], charindex('-', T0.[U_I_LongDesc])
    from [dbo].[RDR1] T0
    Gives "Must specify table to select from".
    This works fine (without charindex):
    Select T0.[docentry], T0.[U_I_LongDesc]
    from [dbo].[RDR1] T0
    Also the original query works fine in MS SQL Server Management Studio.
    What behind-the-scenes garbage is SAP doing now (like adding "FOR BROWSE" to every select)?

    Thanks Gordon.  You're right it does work on system fields.  After some further digging it appears the problem must be that all alphanumeric UDF's are created as nvarchar(max) in SQL Server, regardless of the length you specify.
    This seems to be a bug in SAP.  The charindex query above fails on all UDF's.
    I defined U_I_LongDesc as Alphanumeric (100) in SAP.  Here's what I see defined in SQL Server Management Studio:
    Dscription     (nvarchar(100), null)             /* SAP field with correct length */
    U_I_LongDesc (nvarchar(max), null)        /* UDF.  Gets set to max for all Alphanumeric fields */

  • Cant get this regex to work, please help

    Hey, its that regex time again:
    i need a regex that matches a string that:
    has any text followed by
    has the following substring: navRelId/1000.1001 followed by
    any text followed by
    not the following substring: resource_type_category_id/2 followed by
    any text
    here is an example of a string that should NOT match this regex because it has resource_type_category_id/2 AND navRelId/1000.1001
    http://localhost:8080/MedicalArea.bsci/,,/navRelId/1000.1001/method/MEDICAL_AREA_RESOURCES_CATEGORY/id/10067361/resource_type_category_id/1/resource_type_id/0/cid/7/seo.serve
    here is an example of a string that SHOULD match this regex because it has
    resource_type_category_id/1 AND navRelId/1000.1001
    http://localhost:8080/MedicalArea.bsci/,,/navRelId/1000.1001/method/MEDICAL_AREA_RESOURCES_CATEGORY/id/10067361/resource_type_category_id/2/resource_type_id/0/cid/7/seo.serve
    ive tried the following regex and it doesnt work:
    //the goal is to have the find() return false -
    public TestSearch(){
    Pattern p = Pattern.compile("(?i).*?navRelId[/=]1000\\.1001.*?(?!resource_type_category_id[=/]2).*?");
    Matcher m = p.matcher("http://localhost:8080/MedicalArea.bsci/,,/navRelId/1000.1001/method/MEDICAL_AREA_RESOURCES_CATEGORY/id/10067361/resource_type_category_id/2/resource_type_id/0/cid/7/seo.serve");
    if(m.find()){
    System.out.println("Match found!");
    } else {
    System.out.println("poop!"); //we want this!
    }This is a pure regex question, so dont tell me to use String.indexOf(), i cant do that, i need to do this with one regex.
    Thanks!

    Because you used a reluctant quantifier in ".*?", the negative lookahead gets applied immediately after "navRelId/1000.1001" is matched. And it immediately succeeds because the "resource_type_etc." substring doesn't appear until later. After that, the final ".*?" is free to match the rest of the string (but doesn't actually match anything; see below for the reason why).
    Lookaheads are slippery; you have to be careful and make sure that (1) they get applied at the right position, and (2) they don't match to much or too little. I accomplished the first goal by making sure the lookahead is always and only applied right after a slash, and the second by anchoring the regex to the "/seo.serve" at the end of the URL.
    By the way, you should never use a reluctant quantifier at the end of a regex. If you're using the matches() method to apply the regex, making the quantifier reluctant has no effect except maybe to slow down the match slightly. If you use find() or lookingAt(), the quantifier will always match the minimum number of times allowed, which is zero in this case.

  • Cant get this app to go away in my app store cant update bc its no longer avabile helppp

    in my app store cant update bc its no longer avabile helppp

    i had the same issue, heres what i did and it resolved my problem...
    Make sure iTunes and app store both are closed...
    Open Finder > Navigate to the side panel, look for Macbook Pro or Air under devices tag (e.g. John's MacBook Pro)
    Then go to Macintosh HD > Applications > Right click ''iTunes'' and click Get Info
    Then scroll down to ''Sharing and permissions'' and make sure to make urself able to "read & write"
    Then right click "iTunes" and click "Move it to Trash" and empty your trash...
    Finally go to www.apple.com > Download new iTunes > Once installation finishes, open AppStore and navigate to "Updates"
    and viola..... the badge is gone!!!!
    You are welcome!!!

  • Generics I cant get this thing going?

    I have a Class declaration:
    public class DataContainer<T extends Row>{
    public doSomething(T t){
    Row has four subclasses - DirtyRow, PostDirtyRow, PreDirtyRow, FilterDirtyRow
    How can I now invoke the doSomething method of the DataContainer with the subtype.
    Something like
    DataContainer dc = new DataContainer();
    DirtyRow dr = new DirtyRow();
    dc.doSomething(dr);
    The freaking compiler does not let me do this ... crying out loud how can we solve this generics with subtype problem.
    Regards and thanx in advance.

    DataContainer contain specific types of Rows which
    gets saved in a collection. As such, we want to
    ensure that a specific instance of DataContainer will
    only contain that type (DC has an add(T t) method).
    The question basically is, how can I call the add
    method passing the super class Row as an argument to
    a DataContainer whose type is not known. Consider
    the following :
    public void addRow(DataContainer<? extends Row> dc,
    Row row){
    dc.add(row);
    This does not work, of course, because of the
    wildcard.Is this what you want?
       public <T extends Row> void addRow(DataContainer<T> dc, T row){
          dc.add(row);
       }

  • Voice memos i cant get this to transfer to my laptop any help please

    voice memos can anyone help with the transfer to my laptop <it is 20 mins long>

    Hello
    i found maybe the best way how to transfer Voice Memo from my iPhone 4i(OS6) to my iMac M.Lion 10.8.2.
    On iPhone
    Note:
    You don't need the computer that You make sync with the iPhone, the thing that its important is that
    Your iMac must to be signed with the same account Apple account as Your iPhone, hope work for iPad & iPod Touch.
    1.Go to Your iPhone in voice memo, after the memo on the right side You have blue arrow click it.
    2.You have tab Share click on it!
    3.From the third option Click on message
    3.A) This is in the case that You dont have Your number as contact.
    4.Send to:?  find Your Mobile number 123-1234-1232 something like this.
    5.Click Send
    On iMac
    6.Open the iMessages You must to see that You received the file,It takes time so wait little bit.
    7.Double click on the message that You received.
    8.Now You see it as iTunes file.
    9.Now You have two options:
        A) Open in iTunes in this option You open the file as it is 8 min, 10, min....etc doesn matter.
        B) Send File
           - again 2 option or to mail or to message
    Well Done

  • Hello. I have MacBook Pro. I have 30,000 photos on iPhoto which is not on the hard drive but on an external hard drive. I have purchased a 2nd external hard drive and I would like to make a copy of my iphoto library onto it. I cant get this to work.

    I have MacBook Pro. I have my iPhoto library on external hard drive only. It has 30,000 photos on it. I have bought a 2nd external hard drive and would like to copy my iPhoto library onto it as a back up. I tried plugging both in and dragging the iPhoto library into the 2nd external harddrive. It looked as though it was working as it said 20 hours, however I then got a message box saying FiNader could not complete the task due to incompatible files. How do I do this please.

    lllaass wrote:
    Yes, you should format the HD.
    A Mac can natively write to a NTSF drive and that is what most drives com formatted with.
    You should use the Mac journaled format.
    Once again you are posting incorrect information
    Until we know what format the drive is it is impossible to state that it must be formatted - that is just a guess
    And a Mac can not Natively write to an NTSF drive - it can natively read it but can not write to it with special software
    And since formatting a drive erases it it is critical to tell users not to format until they have a positively known good backup
    The TOU for these forum state that you should test your answers prior to posting them  --  you obviously are not doing that and you advice is endangering users photos - please only post tested answers
    LN

  • Wat is wrong with this simple query ???

    I am using 10gxe.
    Below is the query which is not working
    Whenever i am executing it a pop up windows is coming up
    and asking me to enter bind variables ..wat shall i do ???
    Here is a prntscrn of the issue .
    http://potupaul.webs.com/at.html
    VARIABLE g_message VARCHAR2(30)
    BEGIN
    :g_message := 'My PL/SQL Block Works';
    END;
    PRINT g_message
    Edited by: user4501184 on May 18, 2010 12:42 AM

    sqlplus "system/sm@test"
    SQL*Plus: Release 10.2.0.2.0 - Production on Tue May 18 12:45:05 2010
    Copyright (c) 1982, 2005, Oracle. All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> VARIABLE g_message VARCHAR2(30)
    SQL> BEGIN
    2 :g_message := 'My PL/SQL Block Works';
    3 END;
    4 /
    PL/SQL procedure successfully completed.
    SQL> PRINT g_message;
    G_MESSAGE
    My PL/SQL Block Works
    SQL>

Maybe you are looking for