Column repeat over and over in a group by

Database Oracle 10 g 2.

I have:
with t                 
as                         
(                        
select '1' AS id1, 'A' AS id2, 2 AS num, 'SPAIN' AS loc, 'Yes' AS loc_valid from dual 
union 
select '1' AS id1, 'B' AS id2, 2 AS num, 'SPAIN' AS loc, 'Yes' AS loc_valid  from dual    
union 
select '1' AS id1, 'C' AS id2, 1 AS num, 'USA' AS loc, 'Yes' AS loc_valid  from dual    
union
select '2' AS id1, 'A' AS id2, 3 AS num, 'USA' AS loc, 'Yes' AS loc_valid  from dual 
union 
select '2' AS id1, 'B' AS id2, 4 AS num, 'UNKNOW' AS loc, 'No' AS loc_valid  from dual    
union 
select '2' AS id1, 'B' AS id2, 4 AS num, 'UNKNOW' AS loc, 'No' AS loc_valid  from dual    
)
Expected result:
id1 num loc
--- --- -----------
  1   5 SPAIN
  2   7 USA
Where:
-id1: Group col id1
-num: summary column "num" (within id1)
-loc: repeated the value of the column "loc"(within id1). "» But only if the "loc_valid" column is 'yes '.

Something like this:

SELECT   id1,
         num,
         loc
FROM    (SELECT id1,
                num,
                loc,
                loc_sum,
                MAX(loc_sum) OVER (PARTITION BY id1) max_loc_sum
         FROM  (SELECT id1,
                       num,
                       loc,
                       COUNT(*) OVER (PARTITION BY id1, loc) loc_sum
                FROM  (SELECT id1,
                              SUM(num) OVER (PARTITION BY id1) num,
                              loc,
                              loc_valid
                       FROM   t)
                WHERE loc_valid = 'Yes'))
WHERE    loc_sum = max_loc_sum
GROUP BY id1,
         num,
         loc
ORDER BY id1

Tags: Database

Similar Questions

  • After the xbox reading disc it saids open the tray, after doing that it repeats again and again

    When a disc is put in, it is read and the message 'open the drawer'. We open on a tray, and then close it. It still reads and still 'open tray' lights. This is repeated over and over again. The game does not load.

    Hello

    You can check this link:
    I would also please contact XBOX support for assistance.
  • How to develop and reduce lines or groups of lines in figures?

    How to develop and reduce lines or groups of lines in figures?

    Thank you

    Casey

    Select the rows (or columns):

    Then, place the cursor on one of the row headings (the numbers on the left):

    so that you see the carat facing downwards, then click here to bring up the context menu for the lines:

    then select "hide selected rows.

  • REP-1213: field refers to the column at a frequency lower than his group

    Is it possible to do a field that is located on a lower level group to be displayed in a group that is at a higher level in the report?

    I have a field that is in a group of lower level on a report, and I want it to appear as a header, a group which is a level above his own group. The field must remain in the original group, but should not appear in the report as a column within the original group but should appear under the heading.

    I tried and received the error REP-1213: reference field column to a frequency lower than his group, but how can I get what I want to do without getting this error? Is there a way to show this field in the header without moving in the group header? Should I create an alias or function or what and how?
    Help, please.

    user8655468 wrote:
    Sorry, I do not seem to get to you. MY report has 2 groups of repetition. The first group student_name, course_code, course_name and the 2nd group academic_year, module_name, module_code and module_grade. Academic_year which is the 2nd group should appear as a Cape as well as the elements of the first group, but may not be moved from its original group because it goes with the modules. The report displays a history of modules of a 1st year student for the current year for the school year the header will present the current academic year for a student.

    I do not understand how I should use a column of synthesis to achieve what I want to do. Please can you explain more. Thank you.

    I think you know about the analytical column. If your school year is filed, you can use it to the analytical column. Being a function of synthesis sum. You take this analytical column to group 1 and select the source of the 2nd group. Then display the 1st frame.

    Hope this will help you...

    If someone useful or appropriate, please mark accordingly.

  • Elements of repeatable subform and XML with the missing fields?

    I'm not an expert but I have one condition where a form will bind to a repetitive xml element, called transactions with elements under each transaction as shown below.

    I can't go to a situation where the XML is missing an optional for one of the p.6.  While I expect the form to display this:

    27/07/2011Deposit5000
    28/07/2011Check
    29/07/2011Transfer1000

    It is, in fact, show this:

    27/07/2011Deposit5000
    28/07/2011Check1000
    29/07/2011Transfer

    So, it is basically boils the credit of 1000 for the 2nd element repetitive rather than leave it empty and add correctly in the 3rd repetitive element.  I don't know that that is how I have the shape or how do I implement the XML binding but can anyone help?  I'm close this by forcing the user to always include an empty element that is repeatable, but it is optional in the schema is not a good thing to force on my callers.

    Thank you very much for the help!

    - < Transactions >

    - < Transaction >
    < Are later to > 2011-07-27 < / are later to >
    < Description > deposit < / Description >
    < > Credit5000.00< /credit>

    < / transaction >

    - < Transaction >
    < Are later to > 2011-07-28 < / are later to >
    < Description > check < / Description >

    < / transaction >

    - <Transaction>

    < Are later to > 2011-07-29 < / are posterior to >

    < Description > transfer < / Description >

    <Credit>1000.00</Credit>

    < / transaction >

    < / > transactions



    Hi, make sure you have to have the line or repeat the subform (just what is the parent of the three fields) related to the element of the Transaction, it must have a binding expression that looks to $. Transaction [*] then the three fields will have the relative binding expression that are similar to the $. Are later and keep them all grouped together on the same line (or a subform).  If the individual fields have expressions of shape connection $. Transaction [*]. Postdatent then you will get the problem describe you. Kind regards. Bruce

  • My Macbook Air uses El Capitan 10.11.5. This operating system repeatedly freezes and the computer must be turned on / repeatedly.  How to solve this problem?

    My Macbook Air uses El Capitan 10.11.5. This operating system repeatedly freezes and the computer must be turned on / repeatedly.  How to solve this problem?

    Hello

    Check if the hard disk needs repair.

    Open the disk utility, located app in HD > Applications > utilities

    Select Macintosh HD on the left then click the first aid tab, and then click Run.

  • Satellite L350D-213 repeated overheating and shuts down

    Hello

    Recently had problems with my Toshiba laptop Satellite L350D-213 of the he repeated overheating and if off, any suggestions as to prevent overheating would be greatly appreciated

    Hello

    There is a lot of advice about the overheating problem.
    First the laptop stops automatically to avoid that the pieces of equipment from damage, the higher temperature may affect parts and this is the reason why the laptop stops.

    Why the temperature is too high?
    Well, maybe the cooling modules does not t run with the best performance because of the dust and debris inside the modules?
    It is mainly the reason why fans do not twist and cannot cool the laptop.

    I recommend to check this and remove dust and debris from cooling vents using a jet of compressed air.

    I do from time to time, and it helps to clean the fans

  • Mirror and rotation of whole groups of components layout

    How it is possible to rotate or whole groups of mirrored components? If you select a group of components and apply the mirror or rotation on each component group feature is mirrored or rotated separately and not as a group.

    Hi Nils,

    It is not really possible.

    If you enable a group of components and try to turn, each component will be rotatet for herself and not as a group.

    Other customers also wanted him have changed, they have created a post in our forum for the exchange of idea.

    http://forums.NI.com/T5/additional-NI-software-idea/MultiSIM-12-0-rotate-a-group-of-components-inclu...

    If you like this idea a cudos and write an own post in this forum. If you have enough fans, our R & D will try to implement this in the future of the versions.

    Best regards

  • When sending emails to the bcc and access to a group, I hit the button send and dates back to the Inbox without sending.

    When sending emails to the bcc and access to a group, I hit the button send and dates back to the Inbox without sending. I even changed users on my pc and it always does.  I closed temporarily add-ons thinking that would help, but did not seem to make a difference.  Can I have a virus?

    Hello

    • E-mail are what customer you referring?

    If you use Windows live mail, then the number you posted is related to windows live and will be much better suited in Windows live forums. Click on the link below.

    Windows Live Solution Center

    http://www.windowslivehelp.com/

  • Windows xp install repeatedly KB2229593 and fails to do so, which is already installed on my computer

    Original title: windows xp wants to repeatedly download and install KB2229593 and fails to do so, which is already installed on my computor

    as above

    Hello

    1 have had any changes made on the computer before the show?

    2. do you get an error message? If Yes, what is the full and exact error message?

    I suggest you to see link and check if it helps:

    Troubleshooting Windows Update or Microsoft Update when you are repeatedly offered an update

    http://support.Microsoft.com/kb/910339

    Let us know if it helps.

  • KB2572073 security update is to repeatedly download and installation

    Hello
    KB2572073 security update is to repeatedly download and installation. When I check on Windows Update reports installed successfully. How can I fix it?

    Hello
    Thanks a lot for your answer. I followed the actions in the link provided, but the problem persisted. To fix it I had to remove the .NET Framework and then reinstall it by using the following procedure. That solved my problem.

    Thank you very much for your help.

    Step 1: Remove the .NET Framework using the removal tool

    ================================

    1. download the tool from the following link:

    http://CID-27e6a35d1a492af7.SkyDrive.live.com/self.aspx/Blog_Tools/dotnetfx_cleanup_tool.zip

    2. save the zip (dotnetfx_cleanup_tool.zip) file from the link above on the local desktop and extract it.

    3. double-click on cleanup_tool.exe to run the tool.

    4. follow the instructions given.

    In the "cleaning product:", please select ".NET Framework - all versions.

    5. click on 'clearing '.

    6. restart the computer.

    Note: Once we have removed the .NET Framework, some applications that have need of .NET Framework runtime database could lose their functions. It's just a temporary problem. The function will return to normal after the reinstallation of .NET Framework.

    After completing these steps, please go to the following suggestions to reinstall .NET Framework 1.1 and its updates.

    Step 2: Install the .NET Framework 1.1 and its updates

    ============================================

    Please download and install the following updates in the order.

    Microsoft .NET Framework Version 1.1 redistributable package

    http://download.Microsoft.com/download/a/a/c/aac39226-8825-44Ce-90E3-bf8203e74006/Dotnetfx.exe

    Microsoft .NET Framework 1.1 Service Pack 1

    http://download.Microsoft.com/download/8/b/4/8b4addd8-E957-4dea-BDB8-c4e00af5b94b/NDP1.1sp1-KB867460-x86.exe

    Security Update for Microsoft .NET Framework Service Pack 1 (KB2416447)

    http://download.Microsoft.com/download/6/D/C/6DC6FFA8-4585-4192-A366-85712491322D/NDP1.1sp1-KB2416447-x86.exe

    «Note: when the window "file download" appears, please click 'Save' and follow the directions to save the file to the desktop.» After downloading all the installation files, please double-click on each to install.

  • 5 updates are repeat time and time again the download and installation. How can I stop this?

    These 5 updates are repeating again and again after the download and installation. How can I stop this?
    Update of security for Microsoft .NET Framework 4 on Windows XP, Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008 x 86 (KB2487367)
    Update of security for Microsoft .NET Framework 4 on XP, Server 2003, Vista, Windows 7, Server 2008 x 86 (KB2656351)
    Updated for MICROSOFT.NET Framework 4 on Windows XP, Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008 x 86 (KB2468871)
    Updated for MICROSOFT.NET Framework 4 on Windows XP, Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008 x 86 (KB2533523)
    Update for Microsoft .NET Framework 4 on XP, Server 2003, Vista, Windows 7, Server 2008 x 86 (KB2600217) upwards
    Whenever the foregoing downloads and installs and updates installed successfully. Then a few minutes later he agains says ready to install updates and it's the same updates. Even after restarting my pc, updates moved again.
    Please, I'm desperate to stop it.

    Very well. Welcome & thank you for your comments.

  • I get the same files repeat KB and how to stop it?

    I get the same files repeat KB and how to stop it?

    The KB record number are KB2478663 and KB2518870.

    Mike

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-windows_update/how-to-stop-the-KB-file-from-keeping-repeating-to/21fb21b2-9a13-4261-9c1a-e7ef90a9e6a0

  • I am in Windows Live Mail and cannot send a group.

    Original title:

    I am in Windows Live Mail and cannot send a group. Instructions for individually, click the contact that is listed in the group. Too demanding.

    I'm unable to send emails to a group. Get the message click on individual contacts. How can I change this.

    Click on the name of the group.  Alternatively, the address book by clicking on the name of the group, and then click "new email to the group."

  • I have a problem with the Narrator, repeating words and phrases.

    original title: NARRATOR in WIN7 SUPPORT

    I use windows7.  The annoying Narrator sometimes voices repeat words and phrases.  I also need help, change of voice and using Narrator to read aloud my text book I downloaded.  It is in PDF format.

    Original title: Narrator sometimes repeat words and phrases

    Hello

    Thanks for posting your query in the Microsoft Community.

    You have a problem with the Narrator, repeat words and phrases. It can be difficult when something that is important to you does not work as expected. It's pretty simple and we're here to help you solve the problem. We work as a team and get this sorted out.

    Please answer these questions-

    (1) exactly where you run the Narrator?

    (2) the Narrator extends from a particular document?

    (3) have you made changes on the computer before the show?

    I would like more information about the issue.

    Method-

    I wish that return you the items for assistance-

    Narrator doesn't read what I expect him

    http://Windows.Microsoft.com/en-us/Windows7/Narrator-doesn

    Hear text read aloud with Narrator

    http://Windows.Microsoft.com/en-us/Windows7/hear-text-read-aloud-with-Narrator

    Let us know if you need assistance regarding the issue. We will be happy to help you. We at Microsoft, strive for excellence and provide our customers with the best support.

    Thank you.

Maybe you are looking for

  • HP 6812: hp 6812

    Trying to scan to a USB key.  It worked yesterday but not today.  He says the original is loaded, but when I press start scan it just brings.  I pressed motto of memory, size of the file type and paper, start scanning... bing

  • No DVD-ROM after recovery - Satellite A100-289

    I recently had my A100-289 expedition in for repair. A few days later the unit returned to me with a new motherboard.Unfortunately my OS has not started, so I got it from the DVD. Once you have completed the recovery process, Windows MCE prompted wit

  • How do I report counterfeit software

    Unfortunately, I fell victim of rogue software, I have tried to report to report counterfeit Microsoft but when I enter the license code, microsoft says that it is a valid product key, so I'm not able to continue to the next page to complete the repo

  • LifeChat LX-3000 microphone problem

    Hello. My LX-3000 works well with the sound, but the microphone does not work. What I have to install any driver? I installed Windows Seven about 3 days ago and so far, I don't have it still works. Can someone give me a hand, please? Sorry for the ba

  • Conversion of Standalone put in Cluster Mode of interconnection fabric UCS

    Dear all, I have an environment, where the configuration is done on the stand-alone version FI. Now the customer has purchased another FI. Ask that let me know the best practice to convert the stand-alone version FI in cluster mode. If someone can sh