SQL query to meet all the conditions.

ID of country client_name

a                      india        1

a                     US            1

oneWE1

b                      india         1

c                      india        1

c                      india         1

c                      india         1

c                     us             1

c                    US            1

If I do a count if the id of group by client_name and country column I'll get value like that...

client_name country count (id)

a                  india          1

a                    US          2

b                  india          1

c                  india          3

c                   US           2

Condition of the obligation:

(1) if the customer is in effect in several countries then show that the customer and country having count (id) > 2, (over the case it will be customer = 'b' and country India, country will be us skip)

(2) if the customer is does not exist in several countries then show that client and default country (in above cases it will be customer = 'b') while count (id) is less than 2., we show him...

Catch for me is :-also, we should not ignore any customer... so, as in a. customer... as count (id) for the two countries is not more than 2... so, as per above logic... this client will ignore if we apply only above two conditions

but we need to show the customer in this case... and take the two value... so my end result I need will be:

customer country

a India

a                    US

b the India

c India

Please suggest the query to achieve even... I am able to get the query that meets condition 1 and condition 2. but failure to have taken also in request... so in my query output is all above, except customer one is ignored

Thank you very much!

Hello

I think I see.  You want to display the lines of 'best' available for any client, where the lines with a COUNT (*) 2 > are 'better' than the lines with COUNT (*) <= 2. ="" if="" a="" client="" has="" any="" rows="" with="" count="" (*)="">2, then to display the lines were COUNT (*) > 2, but if all the lines for a customer have COUNT (*)<= 2,="" then="" those="" are="" the="" "best"="" rows="" available,="" so="" you="" want="" to="" show="" them. ="" how="" many="" different="" countries="" a="" client="" is="" related="" to="" doesn't="">

I always CREATE TABLE and INSERT statements for your sample data, so I'll we table scott.emp to illustrate.  Instead of customer and country, as at your table, we will use deptno and job.  This query:

SELECT deptno, job

AS cnt ACCOUNT (*)

FROM scott.emp

GROUP BY deptno, job

ORDER BY deptno, cnt

;

display the relevant data, i.e.:

DEPTNO JOB CNT

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

10. THE CHAIRMAN 1

MANAGER 10 1

10 1 CLERK

20 MANAGER 1

20 2 ANALYST

20 CLERKS 2

30 1 CLERK

30 1 MANAGER

30 4 SELLER

But we don't want to show all the data.  We want to only show the best available for each deptno line type, where the lines with the cnt > 2 (let's call these lines of class 'A') are better then with the NTC<= 2="" (let's="" call="" these="" class="" 'b'="" rows.) ="" the="" output="" we="" want="">

DEPTNO JOB CNT

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

10. THE CHAIRMAN 1

10 1 CLERK

MANAGER 10 1

20 CLERKS 2

20 MANAGER 1

20 2 ANALYST

30 4 SELLER

Deptnos 10 and 20 only have rows of 'B' class, if we want to display the lines of 'B' class for these deptnos.  DEPTNO 30 has at least 1 row of class 'A', so we only show the lines of 'A' class of deptno = 30.  This is an example of a Query of Top - N, and here's a way to do it:

WITH got_r_num AS

(

SELECT deptno, job

AS cnt ACCOUNT (*)

DENSE_RANK () OVER (PARTITION BY deptno

ORDER OF CASES

WHEN COUNT (*) > 2

THEN "A".

OF ANOTHER 'B '.

END

) AS r_num

FROM scott.emp

GROUP BY deptno, job

)

SELECT deptno, job, cnt

OF got_r_num

WHERE r_num = 1

;

Tags: Database

Similar Questions

  • SQL query to extraxt all the virtual folder created in an interval

    Hi all

    I need to extract all the virtual folder created at the Complutense University of MADRID in and the time interval.

    Sameone can you tables me in the schema of the AAU to poll or give me a hint?

    Concerning

    Hello

    If this Folders_g then follow these steps:

    Select dCollectionID, dCollectionName from the collections where dCreateDate > TO_DATE ('2015-01-01', ' YYYY-MM-DD "")

    If it is FrameworkFolders:

    Select fFolderGUID, fFolderName from FolderFolders, FrameworkFoldersHistory where FrameworkFoldersHistory.fItemGUID = FolderFolders.fFolderGUID

    and FrameworkFoldersHistory.dActionDate > TO_DATE ('2015-01-01', ' YYYY-MM-DD "")

    I hope this helps.

    Thank you

    Srinath

  • PL/SQL Query return function, adding the column links

    Hi all

    I'm working on a SQL report with the area type = function from PL/SQL Query to return
    All columns are generated dynamically based on my mapping table and a column of ID.
    So whenever the page is loaded, according to the ID mapping table returns a set of columns in a particular order.
    So not only the columns are dynamic, but the order of the columns varies also.
    But the first 1 column is standard (it doesn't come from the mapping table) and is coded in my pl/sql block hard.

    I'm fighting with the addition of a link to this column. The link must be a Javascript function which takes the parameters in the form of 2 columns in the mapping table.
    My pl/sql block is something like that...
    v_select := 'SELECT <g href=javascript:f_report1(#map_id#,#comments#)><img src=""></a> as report1, ';  // g=a
    v_cols := 'contains all columns from the mapping table based on a ID(hidden item)';
    v_from := 'FROM table';
    v_where := 'where condition is put in here';
    v_query := v_select||v_from||v_where;
    return v_query;
    Now, I'm not able to transmit the values of this #map_id # and #comments # correctly. I tried so many different combinations of channels, but could not make it work.

    I'm not sure that the order of this map_id and commentscolumn and therefore cannot connect through the report attributes.
    How can I go to a column value to the function?



    Thank you
    Dippy

    This should work if all goes well:

    v_select := q'[ SELECT '' as chart, ]';
    

    Published by: Dimitri Gielis on May 20, 2010 20:10

  • SQL query to view all build profiles, properties and values.

    I am trying to create a SQL query to retrieve all our profiles of construction, their properties and their values. The output should include the build profile name, the name of the property and the property value. I found the following tables and just need to understand the appropriate query. I still think that it is a kind of JOIN.

    SELECT [Id]

    [EntityID]

    [PropertyName]

    [Valeurpropriete]

    [IsHidden]

    [IsRuntime]

    [IsEncrypted]

    FROM [VCAC_DB]. [dbo]. [GlobalProfileProperties]

    SELECT [GlobalProfileID]

    [ProfileName]

    [Description]

    FROM [VCAC_DB]. [dbo]. [GlobalProfiles]

    Does that help?

    SELECT GlobalProfiles.ProfileName, GlobalProfileProperties.PropertyName, GlobalProfileProperties.PropertyValue

    OF GlobalProfiles

    INNER JOIN GlobalProfileProperties ON GlobalProfiles.GlobalProfileID = GlobalProfileProperties.EntityID

    I also like this because it gives all the details on the individual custom properties in a profile of construction (such as IsHidden, which tells you if the DEM will treat the property):

    SELECT GlobalProfiles.ProfileName, GlobalProfileProperties.*

    OF GlobalProfiles

    INNER JOIN GlobalProfileProperties ON GlobalProfiles.GlobalProfileID = GlobalProfileProperties.EntityID

  • Cannot install Trend Micro 2012, receive error message: "your computer meets all the installation requirements, so Setup must stop."

    Original title: Problems installing Trend Micro 2012

    Tried to install Trend micro on my laptop, and towards the end of this way the message; "Your computer meets all the installation requirements, so the installer must stop." appeared. He then read "Windows update," I clicked on the link and also called microsoft who gave me the link updates from SP1 to SP2. I did (ran for almost 2 hours!) and recorded. I then checked the edition of windows under system and it has not saved the update even if it is registered and installed to my files. Tried to do the foregoing twice, still the same problem. Rang Dell and they sought to find an answer to the problem, but did everything they could. Still no answer to the problem after all. I have Windows Vista Home Basic as my operating system and installed Trend micro in the past with no problems. (Not sure if the following has nothing to do with it, but thought it might be useful a mention). I changed to Microsoft Office 2007, which has already been installed on my laptop for Office 2003, because I found it difficult from the laptop to the desktop and I didn't really want to pay for the upgrade of my office, if I didn't need it.

    Hello

    You need to install Trend Micro Titanium 2012 Vista SP2 or later version

    See this: http://support.antivirus.co.UK/trendmicro/kbresolution.jsp?Hmid=53756&ServiceId=51&ApplicationId=345

    I suggest you follow these methods and check.

    Determine if SP2 has been installed or not?

    To see if the update has been installed, review the installation history

    To view the history of installation, follow these steps:

    a. click Start, point to all programsand then click Windows Update or Microsoft Update.

    b. click view update history.

    c. find the latest entry for the specific update.

    d. If the entry shows the success in the status column, the update has been installed. If it says pending in the status column, the update is not installed.

    Post back with the history state of Windows update, mistakes, if there is.

    If the update is successful, if it does not show in system properties run System File Checker tool.

    To do this, follow the steps in this link:

    Follow the steps in this link: http://support.Microsoft.com/kb/929833

    In the meantime, you can check this link for the required components, that you must take to install the Vista SP2. Learn how to install Windows Vista Service Pack 2 (SP2)

    http://Windows.Microsoft.com/is-is/Windows-Vista/learn-how-to-install-Windows-Vista-Service-Pack-2-SP2

    Also these return these items:

    Troubleshoot installing or uninstalling programs

    http://Windows.Microsoft.com/en-us/Windows-Vista/Troubleshoot-installing-or-uninstalling-programs

    How to solve problems when you install or uninstall programs on a Windows computer

    http://support.microsoft.com/kb/2438651

    I hope this helps!

  • How to filter data according to internal application and in case if returns nothing outside the query must return all the lines

    create table ab (a number, b varchar2 (20));

    Insert into ab

    Select rownum, rownum. "" sample "

    of the double

    connect by level < = 10

    create table bc (a number, b varchar2 (20));

    Insert into BC.

    Select rownum + 1, rownum + 1 | "" sample "

    of the double

    connect by level < = 10

    Select * AB

    where b in (select b BC where b = "2sample")

    This query will return me 1 row, but there are cases where the value of the parameter b is null

    and that it should return all rows in the table

    as

    Select * AB

    where b in (select b BC where b = "2sample")

    which return specific values, but I want to change in a way when the inner query returns nothing then outer query should return all the lines and works as

    Select * AB;

    Is it possible to put in a single query

    Hello

    You seem to ask for different things.  You want all the lines AB when

    1. The parameter ("2sample' in the example) is NULL, or when
    2. There is no corresponding row in the 2 tables (which could happen even if the parameter is not NULL)

    ?

    Assuming you want the option 2, here's one way:

    WITH got_rnk AS

    (

    SELECT ab.*

    DENSE_RANK () (ORDER IN CASE

    WHEN b (IN)

    SELECT b

    BC.

    WHERE b = "2sample" - parameter

    )

    THEN "A".

    OF ANOTHER 'B '.

    END

    ) AS rnk

    AB

    )

    SELECT a, b

    OF got_rnk

    WHERE rnk = 1

    ;

    This does not assume b is unique in each table.

    Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.

  • During the installation process of 6 of Lightroom, I get a box that says: Windows Vista not supported.  I have Windows 7 with Service Pak1. I meet all the other requirements listed.

    During the installation process of 6 Lightroom, I get a box that says 'Windows Vista not supported'.  I have Windows 7 with Service Pak 1.  I meet all the other requirements listed.  Any ideas?

    Hi Chuck,

    You can check out the link below.

    trying to install lightroom 6 on windows 7 continues to receive operating requirement not met windows vista not supported

    Hope this will help you.

    Kind regards

    Hervé Khare

  • "All the conditions are met" - not exactly?

    Hello again! I'm experimenting a little, set up a mock up of the slightly more complicated project of Captivate to help some of my practice of co-workers with Captivate. I am under a problem but with one of my examples:

    I put a map of the world and six text entry areas to invite a user to name the continents (except Antarctica). I attributed to each box TE an associated variable where it is placed, that is the entrance area of text on Europe is associated with linked a variable titled 'in Europe. I want the slide does not advance until all mailboxes of YOU are properly labelling of each continent.

    Currently, for each main entry text box, rather than by a single shipment, a peak action occurs which assigns the associative variables with a literal name. For example, for action advanced in North America, marked NA_Check, it has an action to display a caption saying 'okay' and assign the NorthAmerica variable with a literal: "North America".

    An advanced global action runs when a user is trying to push a "Continue" button that checks the State of the variables. The conditional action because its properties 'if' that all the conditions are met with Asia = 'Asia', Africa = 'Africa', etc. of all human beings "AND". I assumed that with all of them being 'AND' they must all be true for this check properly. However, I have separate legends for the success or failure, and for some reason all I have to do is to get two correct and I can go forward as if I was 100% correct.

    I thought that maybe it had to do with the variables being assigned prematurely, so I made an action on enter which assigns each variable with "0" so that the entry in the text box would be the only way to make the correct variables. This doesn't seem to work. Any thoughts? Why only do two of the 6 conditions for success when I list all necessary?

    I'm not sure. Maybe a bug in the code of Captivate?

    I think I might rather assign some values to variables and do some calculations, and proceed only if the result is equal to a specific value.

    But that's just me... Rick

  • A query to return all the SQL executed for a particular user instructions.

    Hello

    Is it possible to find all the instructions SQL for a particular user using the views v$? I can do it 10g but I am currently using 9i, the query below does not work.
    select a.username,a.logon_time,b.sql_fulltext 
    from v$session a,v$sqlarea b 
    where a.sql_id=b.sql_id
    and a.username='USER'
    order by a.logon_time desc
    I guess that some columns in these views do not exist in 9i. The output of 9 that I use is 9.2.0.1.0.

    Your help is very appreciated.

    Thank you
    Select this option.

    Dear mark!

    I suggest you use the audit instead of v$ sqlarea. Onlinedocumentation said the next thing Oracle v$ sqlarea:

    >
    V$ SQLAREA lists statistics on the shared SQL area and contains a line by the SQL string. It provides statistics on SQL statements that are stored, analyzed and ready for execution.
    >
    This means that you will only get the SQL statements that are currently in memory. Older statements which are already deleted from memory are not visible for your query.

    Incidentally, if you simply want to know what's wrong with your query then please post your errormessage.

    Yours sincerely

    Florian W.

    Published by: Florian W. the 29.07.2009 12:03

  • Database SQL query to get all virtual machines with comments enabled customization?

    Hello

    Does anyone know of a SQL query that can be executed against the vCloud Director DB for all virtual machines who invited enabled customization?

    I can't have PowerShell to pull these data on a global scale.

    Thank you

    jkasal

    Has taken a quick...

    Select top 10 v.id, v.name, v.vapp_name, v.vc_id, v.moref, ui_vapp_vm_list_view v.guest_customize_enabled v with (NOLOCK)

    seems to have if the setting is enabled or not.

  • SQL query for roll up the amounts from more down to the highest level

    with data (select child 'C', 'P' as a parent, 11 amount of double

    the Union all select 'C1', 'C',-2 double

    Union all select 'C2', 'C', 3 double

    the Union all select 'C3', 'C',-8 double

    Union all select 'C4', 'C', 10 double

    Union all select 'C11', 'C1', 7 double

    the Union of all select them 'C12', 'C1', double 12

    Union all select "C21", "C2", 5 double

    Union all select "C22", "C2", 9 double

    Union all select 'C31', 'C3', 6 double

    the Union all select 'C32', 'C3',-4 double

    the Union all select 'C41', 'C4',-3 double

    the Union of all select them "C42', 'C4' 13 doubles

    the Union of all select them "C111", "C11", 16 doubles

    Union all select 'C121","C12", 8 double

    ) Select * from given by 2

    Hi Experts,

    I have the following table with the child-parent relationship which I would like to roll up from a lower to a higher level. The problem here is that I'm moving the level I should replace the amount for a parent with the overall value of his children and grand total aggregate amount should be c

    For example; In the example given the c111 data roll up to c11 as 16 (Please note: the amount for c11 is 7 should not be added to 16 rather replaced by 16) that more should roll up to c1.

    That means c1 = c11c12; c11 = c111 = 16 Yes, c1 = 16instread 12 16712.

    Since it is an intermediate table, I don't have any control over how many levels it can contain.

    So dynamically, I need a rollup query and group the amount of a lower to a higher level from the bottom.

    Is this possible? I look forward to any help. Thanks in advance.

    SQL > data
    () 2
    3. Select 'C' child, 'P' as a parent, 11 amount of double
    4 union all select 'C1', 'C',-2 double
    5 Union all select them 'C2', 'C', 3 double
    6 Union all select them 'C3', 'C',-8 double
    7 union all select 'C4', 'C', 10 double
    8 union all select 'C11', 'C1', the double 7
    9 Union all select 'C12', 'C1', 12 dual from
    all the 10 union select "C21", "C2", 5 double
    all the 11 union select "C22", "C2", 9 double
    12 union all select 'C31', 'C3', 6 double
    all the 13 union select 'C32', 'C3',-4 double
    14 union all select 'C41', 'C4',-3 double
    all the 15 union select 'C42', 'C4', 13 from dual
    all the 16 union select 'C111","C11", 16 of the double
    all the 17 union select 'C121","C12", 8 double
    18)
    19, data1
    20 in accordance with
    (21)
    22 Select parent
    23, child
    24, lpad ('-', (level 1) * 3, '-'). parent tree_structure
    25, amount
    26, case when connect_by_isleaf = 1 then amount 0 otherwise end amount_leaf
    27 data
    starting 28 with parent = 'P '.
    29 to connect
    30 per parent prior child =
    31)
    32 Select parent as a node
    33, tree_structure
    34, amount_sum
    35 of Data1
    model 36
    size 37 by
    (38)
    39 children
    40, parent
    41)
    42 measures
    (43)
    44 amount_leaf as the amount
    45, tree_structure
    46, 0 amount_sum
    47)
    automatic control of 48 rules
    (49)
    50 amount_sum [none, none] = amount [cv (), cv ()] + nvl (sum (amount_sum) [all cv (child)], 0)
    (51);

    ŒIL TREE_STRUCTURE AMOUNT_SUM BLINK
    --- ------------------------- ----------


    P   P                                 50
    C   ---C                              24
    C1  ------C1                          16
    C11 ---------C11                      16
    C1  ------C1                           8
    C12 ---------C12                       8
    C   ---C                              14
    C2  ------C2                           5
    C2  ------C2                           9
    C   ---C                               2
    C3  ------C3                           6
    C3  ------C3                          -4
    C   ---C                              10
    C4  ------C4                          -3
    C4  ------C4                          13

    15 selected lines.

  • Production PL/SQL query: can not find the error

    I have a PL/SQL which produces a query for me, which is used to fill out a report. I use this to supply a filter/search form. Since I want to only filter using xxx movies WHERE = yyy when yyy actually has something else NULL, I use a PL/SQL script in the query I need to produce. However, it does not work as expected and I can't understand why. Here is my code:
    DECLARE
      query VARCHAR(1000);
    BEGIN
      query := 'SELECT * FROM F_OBJEKTE WHERE 1=1 ';
      IF :P15_REGION != null THEN
        query := query || 'AND REGION = :P15_REGION ';
      END IF; 
      RETURN query;
    END;
    However, the report still contains all lines, as if P15_REGION has not been defined - and so I guess that the script never enters the IF part. Everyone around who can enlighten me, why it is?

    Just another little thing: is there a way I can print debugging messages I see when I press the "Debug" button on the lower bar of APEX? It would help a lot of debugging such PL/SQL functions.

    Try changing

    IF: P15_REGION! = null THEN

    TO

    IF: P15_REGION is not null THEN

  • Improve a simple select query that uses all the lines.

    Hi all

    Excuse me if the question is too dumb. Here is my code
    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    
    Elapsed: 00:00:00.07
    SQL> show parameter optim
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    object_cache_optimal_size            integer     102400
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.1
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     100
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    plsql_optimize_level                 integer     2
    
    SQL> explain plan for select SUM(decode(transaction_type,'D',txn_amount,0)) payments_reversals,
      2          SUM(decode(transaction_type,'C',txn_amount,0)) payments,primary_card_no,statement_date
      3             from credit_card_pymt_dtls  group by primary_card_no,statement_date;
    
    Explained.
    
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    -----------------------------------------------------------------------------------------------------------------------
    -----------------------------------
    Plan hash value: 2801218574
    
    ----------------------------------------------------------------------------------------------------
    | Id  | Operation          | Name                  | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT   |                       |  1912K|    56M|       | 21466   (3)| 00:04:18 |
    |   1 |  SORT GROUP BY     |                       |  1912K|    56M|   161M| 21466   (3)| 00:04:18 |
    |   2 |   TABLE ACCESS FULL| CREDIT_CARD_PYMT_DTLS |  1912K|    56M|       |  4863   (3)| 00:00:59 |
    ----------------------------------------------------------------------------------------------------
    
    9 rows selected.
    
    SQL> select index_name,index_type
      2  from all_indexes
      3  where table_name = 'CREDIT_CARD_PYMT_DTLS';
    
    INDEX_NAME                     INDEX_TYPE
    ------------------------------ --------------------
    INDX_TRANTYPE                  BITMAP
    INDX_PCARD                     NORMAL
    INDX_PSTATEMENT_DATE           NORMAL
    The query uses all records in the CREDIT_CARD_PYMT_DTLS table. Transaction type will be either 'C' or '.

    CREDIT_CARD_PYMT_DTLS has 2 million lines and the qury will display 1.5 million lines. Table statisticas are up to date.

    The query takes now almost 5 minutes. Y thaere a way to reduce the time?

    Our DB server has 8 processors and 8 GB of memory. Is it authentic?

    Thanks in advance.

    Published by: user11115924 on April 29, 2009 02:43
    All columns used in the query are already indexed. (Of course, not only for this query.)

    I should not get too hung up the full Table Scan necessarily - Oracle makes a decision, and even with your new index, he still thinks it is the most effective way to recover the data.

    Did you collect statistics on this new index?

    You have created the index with:

    TO_CHAR("STATEMENT_DATE",'MON-RRRR')
    

    Yet, you seem to be just by selecting statement_date in your query: Oracle cannot use the index (according to functions) in this case!

    If you have only a small number of columns in this table, you can consider an Table of Index organized (ITO), then the table itself is a clue.

    I'd be more inclined to optimize the complete analysis of the table and the creation of other clues, I would say, have you tried the PARALLEL tip?

  • Query to find all the tasks that were running for a particular user

    Hi all

    When you see the 'history of resource' of a particular resource for a user, we can see all the tasks that have been completed for the user.

    I have a requirement which is, I need to display the same information via a database query.

    Any help in this regard will be highly appreciated.

    Kind regards.

    OSI table contains the final task instance data.  If you see a task rejected 5 times, it will be so only one entry of osi.

    Select usr.usr_login, obj.obj_name, mil.mil_name, sch.sch_status

    OSI, mil, CHS, orc, pkg, usr, obj

    where osi.mil_key = mil.mil_key

    and osi.sch_key = sch.sch_key

    and osi.orc_key = orc.orc_key

    and orc.usr_key = usr.usr_key

    and osi.pkg_key = pkg.pkg_key

    and pkg.obj_key = obj.obj_key

    and upper (usr.usr_login) = upper(:usr_login)

    and upper (obj.obj_name) = upper(:obj_name)

    You can provide the user login name and resources, and this will provide you with all their tasks given.

    -Kevin

  • SQL query help needed in the Clause type

    Hello

    I'm currently learning Clause type. How can I write in the clause type to get the result below:

    I have a table like this

    DEPTNO ENAME

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

    20 SMITH

    CELINE 10

    BOND 20

    ALLEN 30

    WARD 30

    20 JONES

    30 MARTIN

    30 BLAKE

    10 CLARK

    SCOTT 20

    10 KING

    30 TURNER

    20 ADAMS

    30 JAMES

    20 FORD

    10 MILLER

    I want the output should look like this

    DEPTNO ENAME

    ------     -----

    CELINE 10, CLARK, KING, MILLER

    20 JONES, ADAMS, BOND, FORD, SCOTT, SMITH

    30 MARTIN, JAMES BLAKE, WARD, TURNER, ALLEN

    Hear is the script I am currently working on.

    with emp_group as

    (

    Select 20 deptno, ename 'SMITH' Union double all the

    choose 10, 'CÉLINE' from dual union all

    Select 20, "BOND" of all the double union

    Select 30, 'ALLEN' from dual union all

    Select 30, 'WARD' of all the double union

    Select 20, "JONES' from dual union all

    Select 30, 'MARTIN' from dual union all

    Select 30, "BLAKE" from dual union all

    choose 10, 'CLARK' from dual union all

    Select 20, 'SCOTT' from dual union all

    choose 10, 'KING' of the dual union all

    Select 30, 'TURNER' from dual union all

    Select 20, 'ADAMS' from dual union all

    Select 30, 'JAMES' of the dual union all

    Select 20, 'FORD' Union double all the

    choose 10, 'MILLER' from dual

    )

    Select

    DEPTNO

    A1

    of emp_group

    model

    ignore the nav

    partition (deptno)

    dimension (ROW_NUMBER() over (PARTITION BY deptno ORDER BY ename DESC) rn)

    measures (ename, LPAD(' ', 100) A1)

    rules)

    A1 [rn > 0] = ename [cv ()],

    A1 [0] = ename [cv ()]

    )

    order by deptno

    ;

    your help is very appreciated.

    Thank you in advance.

    Try this.

    Select

    *

    Of

    (

    with emp_group as

    (

    Select 20 deptno, ename 'SMITH' Union double all the

    choose 10, 'CÉLINE' from dual union all

    Select 20, "BOND" of all the double union

    Select 30, 'ALLEN' from dual union all

    Select 30, 'WARD' of all the double union

    Select 20, "JONES' from dual union all

    Select 30, 'MARTIN' from dual union all

    Select 30, "BLAKE" from dual union all

    choose 10, 'CLARK' from dual union all

    Select 20, 'SCOTT' from dual union all

    choose 10, 'KING' of the dual union all

    Select 30, 'TURNER' from dual union all

    Select 20, 'ADAMS' from dual union all

    Select 30, 'JAMES' of the dual union all

    Select 20, 'FORD' Union double all the

    choose 10, 'MILLER' from dual

    )

    Select

    DEPTNO

    names

    rn

    of emp_group

    model

    ignore the nav

    partition (deptno)

    dimension of)

    ROW_NUMBER() over (PARTITION BY deptno ORDER BY ename) rn

    )

    measures (ename, cast (null as names of varchar2 (40)))

    rules

    (

    names [any] order by desc = ename [cv ()] rn | «, » || names [cv () + 1]

    )

    order by deptno

    )

    where rn = 1

    Best regards, Andrei

Maybe you are looking for

  • This happens when I hit the home page of chrome://Branding/locale/BrowserConfig.Properties

    When I start firefox the address above appears in the browser bar, and I can't get rid of it. It is now my homepage.

  • Creating DVDs with external burners

    I have a 08 20 "I have mac. The DVD drive is dead. I'm trying to make DVD of a MRX-650LEv5 of the burners from LG-8 X with the mac as the go between. It does not work. I'm I lack a step?

  • Two vista operating system installed, but only starts

    Hello I hope someone could help me to overcome this problem: My laptop with vista venus hm so high-end, as I bought it in Germany had German language. So I bought ultimate in English and do a new installation. I was very happy with it, but yesterday

  • Trouble Y50-70 with drivers intel

    Hi, I'm having a problem installing some drivers intel on my Y50-70, I had some problems with my operating system and decided to downgrade to windows 7 which ended up having the Partition type change that wiped the drive, so I'm here. I am on Windows

  • BIOS and RAM

    Hello ppl, I have a problem with my 650 HP with the RAM, I have a module of 4GB, but the system "because" only 929MB with BIOS F32. I downloaded F37 (later), installed and now it says I had 2, 66GB 4 GB available. This is obvious progress, but still