Exit help request formatting

Hi all

I have problems trying to format the output of one of my questions. I'm new to SQL and I consider my writing the query to a GREAT victory... but I can't seem to get the correct output format.

With the code below, she's the name (lname) in the employee, a county of what I want and the overall standings.  I want to concatenate the employee number (emp #) the first (fname) and name (lname) together in the same column in the output.

Concatenation code would be something like below.

Desired concatenation:

EMP # | ' - ' || lname | ', ' || fname AS EMPLOYEE


I'm using Oracle 11 g Express. Please let me know if you need any information to help you.

I appreciate your help! Thank you.

Query

SELECT EMPLOYEE, PREPARED,

Rank() over (ORDER BY DESC prepared) AS rank

FROM (SELECT lname EMPLOYEE, COUNT (DISTINCT reportnum) PREPARED

The EMPLOYEE

LEFT OUTER JOIN faultreport using (empno)

GROUP BY lname

ORDER BY DESC prepared)

WHERE rownum < 15;




Hello

Thus, you do not want to group by the concatenated employee, lname not only.  Here's a way to do it:

WITH got_rnk AS

(

SELECT e.empno. ' - '

|| e.Lname

|| ', '

|| e.fname AS an employee

COUNT (DISTINCT f.reportnum) AS prepared

Rank () OVER (ORDER BY COUNT (DISTINCT f.reportnum) DESC)

LIKE rnk

E employee

LEFT OUTER JOIN faultreport f ON f.empno = e.empno

GROUP BY e.empno, e.lname, e.fname

)

SELECT *.

OF got_rnk

WHERE rnk<>

ORDER BY rnk

employee

;

You only need the subquery if you want to limit output employees to the top 14 (or whatever the number).

Analytic functions (for example, RANK) are calculated after the clause GROUP BY has been applied and aggregate (such as COUNT above) functions were calculated.  This is why you can use an aggregate function in an analytical clause (e.g. "RANK () OVER (ORDER BY COUNT...)"

Tags: Database

Similar Questions

  • Need help request!

    Hi all

    I am faced with a request to generate a model:

    The problem is the following:

    I have a test table in

    create table test

    (

    Identification number,

    varchar2 (20 char) value,

    date date

    );

    and the row values are as follows:

    value date: ID:

    1:value1:Date1

    1:value2:date2

    1:value3:date 3

    where date1 is today, date2 is yesterday and date 3 is the day before yesterday.

    I have to generate a format like below:

    ID: old_value:new_value:changed_date

    1:value3:value2:date2

    1:value2:value1:Date1

    where id, old_value, new_value and modified date are columns.

    Any suggestions would be helpful.

    select *
    from (
      select id
           , lag(value) over(partition by id order by dt) as old_value
           , value as new_value
           , dt as changed_date
      from test
    )
    where old_value is not null ;
    
  • HP 50 g RPL program to list the factors needing help the formatted output; Matrices, vectors, lists, etc.?

    Hello

    I have not always perfer the output of the DIVIS HP 50 g.

    DIVIDED lists all the factors of a number in a way that is ineffiecent and confusing when there are many factors of a given number.

    For example, when you run 1000 DIVIS you are treated to a large "block" of numbers organized vertically in such a way that only 4-5 of the 16 factors of 1000 are still visible to you without additional keys.

    I'm trying to create a program that simply formats the output of DIVIS differently when there are a lot of factors for a given number. I'm a newbie to the USER RPL. I have the factors that come out a while loop in this format. (100, 10) Unfortunately, my time loop depends on these factors enters NOT the battery until AFTER he calculated all the. I need to find a way to store a set of factors by the execution of the loop in a kind of variable, and then remind each other both on the stack at the end of the program execution. If the code is necessary for you to see, I can post it. The problem is that it is unclear how many factors will be present at this stage. It will be the original number / 2 because I have through each pair of factor in jurisdiction parens with R-> C. In addition, the capture method must be in the loop because that if it is not the loop won't work correctly because the method by which he organized the factors in their concerned couples depends on a process of battery undisturbed during the execution of the loop. Leaving the parens at the bottom of the battery causes there are an odd number of factors in the stack, which invalidates my program for various reasons. In addition, it would be useful to include a function that could test whether or not the number of factors of an odd number, because I will need to include separate code for this. I don't know any such function in USER - RPL, but I am a beginner in this area. Thanks for any help!

    Zekelegge

    Ranothil wrote:
    (...)

    For 1000, my dream program would output;

    (...)

    Try this:

    ' DUP DIVIS SWAP ON / SWAP R-> C EVAL.

    or:

    "DIVIS DUP DUP SIZE 2 / 1 SWAP SUB DUP UNROT / R-> REVLIST C EVAL.

  • Why is my help requests being deleted?

    3-4 of my requests for help last week disappeared.

    I'm still waiting for assistance.

    My messages were respectful at all times.

    Why is this done?

    Spitfire,

    Maybe they were duplicates, as these two?

    Results of terminal script below for frozen, then slow cursor

    Frozen cursor MacBook Pro 13 "w updates

  • Need help with formatting my laptop Satellite M40

    Dear all,

    I have a satellite M40 notebook and when I bought it was running perfectly. Then the sound has deteriorated significantly with the Harman / Kardon speakers without drastically.
    Then, the speed of the applications has deteriorated in opening. Then I could not use my DVD RW drive to back up my data. In my opinion, happened after I tried to install a software that may be in conflict with the existing drivers.

    Finally, I decided to format the laptop and start over. With my original purchase came three CD: DVD - ROM Recovery DVD-ROM, Express Media Player Recovery CD and additional software.

    I tried the first two CDs, hoping that the laptop start automatically on their part, and then everything will be fine. Unfortunately, nothing has happened.

    Help, please. How can I format this machine and resume my busy days at the office.

    See you soon

    Hello George

    For the installation of an operating system, you need to RECOVERY DVD. Put in the DVD player, turn on the unit and press the C key on the keyboard. Keep it down for a short period and the procedure of the facilities will begin.

    If you want to preinstall the unit I recommend you create two partitions using facilities expert mode. Check it please this subject http://forums.computers.toshiba-europe.com/forums/thread.jspa?threadID=4462&messageID=14518#14518

    There is step by step explanation. If you want to use the Express media player again once it must be installed first before using recovery DVDs. The procedure is the same (press the C key).

    Good bye

  • Run and Exit on request

    Hello, friends! I have a problem and I'll be thanked for all help! I want to create application of my VI with the application builder. I want to remove all the buttons and use the standard toolbars in the application. So, to do this, I need to create buttons Run and output in application. But I don't know how :-( It will be cool, if anyone divides for example, VI, which contains the feature for these buttons! Thank you!

    Here is an attached vi... just an example 9hittimg STOP leaving Labview)

    If you do not want to see the menu bar or the scroll bar and then CTRL + I-> properties-> appearance window VI-> customize and select the option to adapt accordingly.

    Also if you want to stop and exit the application use the "Quit LabVIEW" function available

  • help with formatting of the accidental partition

    I had to re - start my operating system. whem I formatted the drive, I was installing on, I accidentally formatted partitions on one external drive. My question is; is it possible to pull content market back this player. or better yet, restore the partitions on this subject? I have a ton of things in it that I can't replace. any help would be greatly appreciated. and please. keep simple language please. I am a novice at this stuff. Thank you.

    There are 3 third-party programs that should be able to restore partitions or data that were on them. This might work only if you have done a quick format. Quick format just basically says "store data between points A and B", without deleting data that are there, so the data is recoverable. I don't know the names of all the programs, so maybe someone else can help you with that, but I can say until you find a do not do anything with the external hard drive because whatever it is placed on the disk will be overwriting previous data.

  • Help request for C:\windows\system32\config\system / Bad Pool Caller / on xp

    . Hi, I have xp sp3, and after the established cat off for switching on the pc appears the error message mentioned.  I tried f8 for boot from the sp3 installation CD and ends up with the BAD_POOL_CALLER message.  That's why I can't launch 'r' for recovery apparently safe mode.  Any suggestion would be appreciated before gratefully the cat gets it... Thank you.

    Well, if you can start on some CDs and get to a command prompt on your HARD drive, you should be able to implement the suggestion of KB307545 of Microsoft Support Engineer Halima S and "check if it helps" (I don't think it will be).

    Here's how you describe / have symptoms that indicate the need to use KB307545:

    Zero

    If you want to make a bootable CD from the Console of the Recovery XP (no XP media required) and then to implement the proposal of Microsoft Support Enginner Halima S and check if it helps.

    Here's how:

    Boot into the Recovery Console Windows using an XP bootable installation CD.

    If you have no XP bootable media (or aren't sure you have) create a bootable XP Recovery CD of Console and do not forget.

    This is not the same as recovery disks that might have come with the acquisition of the system store.

    You can make a bootable Recovery Console CD by downloading an ISO file and burn it to a CD.

    The ISO bootable image file you need to download is called:

    xp_rec_con. ISO

    Download the ISO from here:

    http://www.mediafire.com/?ueyyzfymmig

    Use a new CD and this simple and free program to burn your ISO file and create your bootable CD:

    http://www.ImgBurn.com/

    When you install ImgBurn, DO NOT install the Ask toolbar.

    Here are some instructions for ImgBurn:

    http://Forum.ImgBurn.com/index.php?showtopic=61

    It would be a good idea to test your bootable CD on a computer running.

    You may need to adjust the computer BIOS settings to use the CD-ROM drive as the first device to boot instead of the hard drive.  These adjustments are made before Windows tries to load.  If you miss it, you will need to restart the system again.

    When you start on the CD, follow the instructions:

    Press any key to boot from CD...

    Installing Windows... going to pronounce.

    Press 'R' to enter the Recovery Console.

    Select the installation that you want to access (usually 1: C:\WINDOWS)

    You may be asked to enter the password (usually empty).

    You should be in the folder C:\WINDOWS.  It's the same as the

    C:\Windows folder that you see in Solution Explorer.

    The Recovery Console allows base as file commands: copy, rename, replace, delete, chkdsk, fixboot, fixmbr, cd, etc.

    For a list of the commands in the Recovery Console, type help at the prompt of commands or read on here XP Recovery Console:

    http://www.Microsoft.com/resources/documentation/Windows/XP/all/proddocs/en-us/recovery_console_cmds.mspx?mfr=true

    When you get into RC, is if you can run a chkdsk/r...  Here's how:

    A good idea before you start things must first verify the integrity of your file system by using the chkdsk command.

    In the command prompt window, run the chkdsk command on the drive where Windows is installed to try to fix any problems on the afflicted player.

    Running chkdsk is fine, even if he finds no problem.  It won't hurt anything to run it.

    Assuming your boot drive is C, run the following command:

    CHKDSK C: /r

    Let chkdsk finish to correct the problems, he could find.

    It may take a long time for chkdsk complete or they seem to be "stuck".  Be patient.  If the HARD drive led blinks always, chkdsk is something.  Keep an eye on the amount of the percentage to be sure that it is still making progress.  It may even seem to go back sometime.

    You must run chkdsk/r again until it finds no error to correct.

    Remove the CD, and then type "exit" to exit the RC and restart the computer.

    You have not to set the BIOS to boot the disk HARD since the CD won't be.

  • 32 GB SANDISK CRUZE GLIDE REQUEST FORMAT (new)

    Hello!

    Well, I just bought the USB last week during a visit in new york (best buy). Now, back in my country (Argentina), I opened the box and she asked for the format. also it only regnizes 64 MB. Format does not work (I tried all different types of formats, fast, slow, fat ntfs, fat32, etc) and several pcs.

    Any help?

    Thank you!!

       Hi Marianogr,

    Dear member of the community of SanDisk, welcome.

    I'm sorry, and then died or is false, ist kaputt o're trucha...
    Return it.

    See the link: http://www.sandisk.com/about-sandisk/contact-us/

    Chance.

    Sincerely, Alfred.

  • Cannot right click Windows 7 Explorer of files to generate the copy of the file names in a Notepad or Excel-compatible file. HELP REQUESTED!

    I struggled for several hours to restore the service right click that I used to have XP to Windows 7.  I need to save lists of file names such as displayed in the file Explorer. Allowing you to right-click and save files in Notepad. This option has been removed in Windows 7 and anything put in place to restore it.

    I have lists of items in the inventory and need to copy and paste the image corresponding to a transfer sheet to allow the server names to match images in article SKU.  The file names are long and typing is a complete waste of time.

    I used to be able to find them in the Windows Explorer, right-click on the directory and generate a txt file that I could open in Notepad or Excel.  -Easy.  Now right-click only allows an export in an uneditable image in ONE NOTE. This is useless for me. I can't do anything with an image file - I need the editable data.

    Is there a solution?  I need only the file name and extension, not the full path, in a text or spreadsheet document propagation.

    I had used the Microsoft solution to install their dose without knowing the final format was a NOTE image file format and not a simple txt file. I try now too write the batch file:

    %windir%\Printdir.bat

    or edit it in order to keep the file in Notepad and do not make the final conversion into a single Note.

    The problem is that the fix from Microsoft, designed to fix this problem, has placed the conversion file in the root directory and it cannot be overwritten.  I refused the possibility to delete, edit or write the file due to the requirements of administrative privilege mandated by the security of Windows 7 too much.

    So if anyone has a solution to every problem - that would help - I am very tired and frustrated and not happy with Microsoft.  Their zealous concern with security made their unnecessary programs for me and have further discouraged me to convert to the windows 10. frustrations and nightmares are waiting for me there I can't imagine.  What I really want to do at this point is to go back to XP.

    He ate five hours of my day. I don't have the time to fight like that. I am trying to be productive, but all I got are monumental technical walls and roadblocks - often designed into the system. Frustrating doesn't begin to describe it.

    Found a solution on a Web site:

    http://www.watchingthenet.com/how-to-print-a-directory-tree-from-Windows-Explorer.html

    They said it was for VISTA, but worked for me under Windows 7. You will need to use Notepad to the command prompt and select run as administrator to save the file in the root directory.

    Thanks for the help.

    Cheers.

  • Help request deleted blackBerry smartphones! I want to go back!

    I accidentally deleted the request for help while trying to remove a third-party application. I was surprised that a, I fact and two, let me not! How do I get it without having to reload all the software completely (and lose all my other apps)?

    Open your Desktop Manager > application loader, run it and CHECK help load.

    If nothing is present in the application loader, you need to charge your current device OS on your PC.

  • Help request NULLIF

    Hi all

    I wrote the request to show that if the sal & comm are same the result should display 'same' thing below, it should display "diff".

    Select nullif (sal, comm), ename

    WCP

    where is nullif (sal, comm) =: nullif (sal, comm)

    then dbms_output.put_line ('same')

    on the other

    dbms_output.put_line ('diff')

    /

    But I get the mentioned error below

    SP2-0552: Bind "NULLIF" undeclared variable.

    Help is kindly solve its appearance like why and what needs to be done.

    Thank you...

    Others have mentioned your errors of syntax and other ways to do the task, but nobody gave the reason for the specific error that you got.  Here it is:

    Select nullif (sal, comm), ename
    WCP
    where if nullif (sal, comm) =: nullif (sal, comm)
    then dbms_output.put_line ('same')
    on the other
    dbms_output.put_line ('diff')

    The equality in SQL and PL/SQL operator is = and in PL/SQL assignment operator : =. There is no =: operator anywhere, if the compiler sees the: nullif as a variable binding.

    John

  • Help: Output Format complex

    Hello

    Data in TAB_DTL for an APPID using, I need to generate a report in the following format.
    CREATE TABLE TAB_DTL
    (
    APPDATE          DATE,
    AMOUNT          NUMBER(12,2),
    STATUS          VARCHAR2(1),
    RATE          NUMBER(5,2)
    );
    
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '13/09/2011 10:50:45 AM','DD/MM/YYYY HH:MI:SS AM'), 500000, 'D', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '09/11/2011 1:15:30 PM','DD/MM/YYYY HH:MI:SS AM'), 5000, 'R', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '15/12/2011 3:20:31 PM','DD/MM/YYYY HH:MI:SS AM'), 5000, 'R', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '05/01/2012 10:25:11 AM','DD/MM/YYYY HH:MI:SS AM'), 5000, 'R', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '02/02/2012 4:23:34 PM','DD/MM/YYYY HH:MI:SS AM'), 5000, 'R', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '05/03/2012 11:15:45 AM','DD/MM/YYYY HH:MI:SS AM'), 5000, 'R', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '30/03/2012 11:55:10 AM','DD/MM/YYYY HH:MI:SS AM'), 5000, 'R', 13 );
    INSERT INTO TAB_DTL ( APPDATE, AMOUNT, STATUS, RATE ) VALUES TO_DATE( '31/03/2012 11:59:00 AM','DD/MM/YYYY HH:MI:SS AM'), 470000, 'B', 13 );
    
    
    OUTPUT FORMAT :
    
    APPDATE                    DR          CR     BALANCE          ACCAMT     DAYS     CUMM      
    13/09/2011 10:50:45 AM          5,00,000.00     0     5,00,000.00     10301     58     10301
    09/11/2011 1:15:30 PM          0          5000     4,95,000.00     6330     36     16631
    15/12/2011 3:20:31 PM          0          5000     4,90,000.00     3655     21     20286
    05/01/2012 10:25:11 AM           0          5000     4,85,000.00     4823     28     25109
    02/02/2012 4:23:34 PM          0          5000     4,80,000.00     5456     32     30565
    05/03/2012 11:15:45 AM          0          5000     4,75,000.00     4218     25     34783
    30/03/2012 11:55:10 AM          0          5000     4,70,000.00     334     2     35117
    31/03/2012 11:59:00 AM          0          0     4,70,000.00     35117
    For the calculation of A logic) DAYS: difference in days of the next later Date
    (B) ACCAMT: Balance * (unlike in the days of the next Date) * rate / days in the year

    With the help of CASE / SQLs of LEAD, the same thing can be accomplished.

    Thank you
  • Urgent help conditional formatting using XML publisher

    Can people all you help me. I'm doing the conditional formatting in my xml editor rtf model and I have problems to render the data in the specific format. Please see the sample xml file

    <? XML version = "1.0" encoding = "UTF-8"? >
    < ColTrn:CollegeTranscript xmlns:AcRec = "urn: org:pesc:sector:AcademicRecord:v1.0.0" xmlns:ColTrn = "urn: org:pesc:message:CollegeTranscript:v1.0.0" xmlns:UseExt = "urn: org:pesc:useextensions" xmlns:core = "urn: org:pesc:core.» "CoreMain: v1.0.0" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "urn: urn http://www.regents.state.oh.us/articulation_transfer/AT/ATC/XML/Standards/Postsecondary/Transcript/v1.0.0/CollegeTranscript_v1.0.0.xsd org:pesc:message:CollegeTranscript:v1.0.0: org:pesc:useextensions http://www.regents.state.oh.us/articulation_transfer/AT/ATC/XML/Standards/Postsecondary/Transcript/v1.0.0/OBRExtensions_v1.0.0.xsd" >
    < student >
    < person >
    < SchoolAssignedPersonID > 0001567740 < / SchoolAssignedPersonID >
    < name >
    < FirstName > WENDELL < / name >
    < MiddleName > ROBERT < / MiddleName >
    < name > MORRISON < / LastName >
    < / name >
    < / person >
    < AcademicRecord >
    < AcademicAward >
    < AcademicAwardLevel > 2.4 < / AcademicAwardLevel >
    < AcademicAwardDate > 2004 - 03 - 20 < / AcademicAwardDate >
    < AcademicAwardTitle > BACHELOR OF SCIENCE IN EDUCATION < / AcademicAwardTitle >
    < AcademicCompletionIndicator > true < / AcademicCompletionIndicator >
    < AcademicCompletionDate > 2004 - 03 - 20 < / AcademicCompletionDate >
    < AcademicAwardProgram >
    < AcademicProgramType > big < / AcademicProgramType >
    INTEGRATED SOCIAL SCIENCES (BS6308) < AcademicProgramName > < / AcademicProgramName >
    < / AcademicAwardProgram >
    < AcademicAwardProgram >
    < AcademicProgramType > minor < / AcademicProgramType >
    < AcademicProgramName > PSYCHOLOGY (OR4101) < / AcademicProgramName >
    < / AcademicAwardProgram >
    < NoteMessage > EDUCATION AND HUMAN SERVICES < / NoteMessage >
    < AcademicSummary >
    < AcademicSummaryType > SenderOnly < / AcademicSummaryType >
    undergraduate < AcademicSummaryLevel > < / AcademicSummaryLevel >
    < GPA >
    < MoyenneNotes > 2.835 < / MoyenneNotes >
    < / GPA >
    < ClassRank > 408 < / ClassRank >
    < > 533 ClassSize < / ClassSize >
    < / AcademicSummary >
    < / AcademicAward >
    < AcademicAward >
    < AcademicAwardLevel > 2.4 < / AcademicAwardLevel >
    < AcademicCompletionIndicator > false < / AcademicCompletionIndicator >
    < AcademicAwardProgram >
    < AcademicProgramType > minor < / AcademicProgramType >
    < AcademicProgramName > HISTORY (OR4211) < / AcademicProgramName >
    < / AcademicAwardProgram >
    < / AcademicAward >
    < / student >
    < / ColTrn:CollegeTranscript >

    I am trying to generate the output in the format - below

    [The University conferred degrees section is printed if/AcademicRecord/AcademicAward/AcademicCompletionIndicator = true and AcademicProgramType = 'Major']

    GRADUATE ACADEMIC (S) CONFERRED *.

    DATE: March 20, 2004 = > < AcademicAwardDate >
    COLLEGE: EDUCATION AND HUMAN SERVICES = > < NoteMessage >
    DEGREE: BACHELOR OF SCIENCE IN EDUCATION = > < AcademicAwardTitle >
    PROGRAM (S): INTEGRATED SOCIAL STUDIES (BS6308) = > < AcademicProgramName >
    ACCUM GPA: 2.835 = > AcademicSummary/GPA/MoyenneNotes
    GRAD RANK: 408 TOTAL OF 533 = > < ClassRank > and < ClassSize >

    [Section must print if the student has 'Minor' = AcademicProgramType and Academiccompletionindicator = true]
    _______________________________________________________
    ANOTHER UNIVERSITY OF PROGRAM (S) IS COMPLETED *.
    DATE March 16, 2002 PROGRAM: PSYCHOLOGY (OR4101) = > < AcademicProgramName > where AcademicProgramType = 'Minor '.

    [Section must print if Academiccompletionindicator = false print all the majors and the minors.]
    _______________________________________________________
    CURRICULUM CURRENT (S)
    PROGRAM (S): HISTORY (OR4211)
    = > AcademicProgramName where AcademicAward/AcademicCompletionIndicator = "false".

    Please help me guys. I really appreciate your help.
    Thank you
    Pradeep

    I sent you a modified model. Please take a look.

    Award points and close the thread if you are satisfied.

    Thank you
    Bipuser

  • Helps the formatting of multi-line output in comma sorted output

    I have 2 tables:
    ####################################
    SQL > table_1 desc;
    Name Null? Type
    ===================================
    ID NOT NULL NUMBER
    DATA1 NOT NULL VARCHAR2 (440)
    DATA2 NOT NULL VARCHAR2 (1024)
    ####################################
    SQL > table_2 desc;
    Name Null? Type
    ===================================
    ID NOT NULL NUMBER
    ATTNAME NOT NULL VARCHAR2 (255)
    ATTVAL VARCHAR2 (4000)
    DATA1 NOT NULL CHAR (1)
    DATA2 VARCHAR2 (2000)
    DATA3 VARCHAR2 (255)
    ####################################
    I need to get ATTVAL where for example ATTNAME = att_name1 to ATTNAME = att_name6 for each entry (with its unique ID) and format the output to the format delimited by commas in for example the following order:
    att_val1, att_val3, att_val6, att_val4, att_val5, att_val6

    So e.g. entry with ID "9812" the query below, the output I need would be:
    187,179,156,134,1436,1809

    What I have so far is the following:
    ####################################
    SQL > SELECT id, attname, attval FROM table_2 WHERE id in (SELECT id from table_1 WHERE data2 = "xxx")
    AND attname in ('att_name1', 'att_name3', 'att_name6', 'att_name4', 'att_name5', 'att_name6');

    ID ATTNAME, ATTVAL
    ===============================
    1970 att_name1 123
    ABC att_name2 1970
    1970 att_name3 1234
    def att_name4 1970
    1970 att_name5 1134
    ghj att_name6 1970

    9812 att_name4 134
    9812 att_name5 1436
    9812 att_name3 156
    9812 att_name1 187
    9812 att_name2 179
    9812 att_name6 1809

    77 att_name1 1980
    77 att_name5 1867
    77 att_name3 174
    77 att_name4 1345
    77 att_name2 1345
    77 att_name6 1345
    ...
    ####################################

    but I don't know how to format the decimal output limited in certain order. (or if it's the best way to get the data)
    Anyone idea how this could be done?

    846954 wrote:
    Thanks Frank!

    I got a lot further now :).
    I've got Oracle 10 g so I used the "SYS_CONNECT_BY_PATH' for my query.

    Now, I get the output in the format I want, however, it comes out in order that are the attributes (which is pretty random).

    The values you have posted are in order: "attval1."< 'attval2'=""><>

    So I use it now (had to use "|" as the separator because SYS_CONNECT_BY_PATH wouldn t with comma because of the attval have comma in them sometimes):

    Do not contain the values that you have posted and commas.

    You hide what is the problem. It would really help if you posted real data. It is always helpful if you post the CREATE TABLE and INSERT statements for some examples of data and outcomes from these data.

    Assuming that you really have something that needs to be in a certain order, and that order is not based on what in the values themselves, then DECODE might be a good way to do it. Store the value of sorting in a table can be even better.

    It seems that you use an exanple Oracle 9. In Oracle 10, using SYS_CONNECT_BY_PATH is simpler:

    SELECT     id
    ,     LTRIM ( SYS_CONNECT_BY_PATH (attval, '|')
               , '|'
               )          AS attvals
    FROM     (
              SELECT     id
              ,     attval
              ,     ROW_NUMBER () OVER ( PARTITION BY  id
                                  ORDER BY          DECODE (...)
                                )     AS curr
              WHERE     id     IN (
                             SELECT  id
                             FROM     table_1
                             WHERE     data2     = 'xxx'
                             )
              AND     attname     IN ('attname1','attname2','attname3','attname4','attname5','attname6')
         )
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     curr     = 1
    CONNECT BY     curr     = PRIOR curr + 1
         AND     id     = PRIOR id
    ;
    

    You don't need two almost identical ROW_NUMBERs; We do it very well.

Maybe you are looking for