First DISTINCT and then Group by

I have few records that have repeating values. I want to sum only the unique values. I am using Distinct clause to get Distinct records and doing group by to get the sum. But it seems like it is doing the sum and then returning the distinct values so my summed value comes out to be incorrect. Is there a way to only SUM the distinct records?

Could you please send us the query, because I tried something like that and it worked.
Wrote file afiedt.buf
1 select deptno, ename, sal from emp
2* WHERE deptno = '20'
3 /
DEPTNO ENAME SAL
20 SMITH 800
20 JONES 2975
20 SCOTT 3000
20 ADAMS 1100
20 FORD 3000
20 TEST100
6 rows selected.
SQL> select sum(DISTINCT sal) FROM emp WHERE deptno = '20';
SUM(DISTINCTSAL)
7875
SQL> ed
Wrote file afiedt.buf
1 select deptno,sum(DISTINCT sal) FROM emp WHERE deptno = '20'
2* GROUP by deptno
3 /
DEPTNO SUM(DISTINCTSAL)
20 7875
SQL> ed
Wrote file afiedt.buf
1 select deptno,sum(DISTINCT sal) FROM emp
2* GROUP by deptno
SQL> /
DEPTNO SUM(DISTINCTSAL)
10 9625
20 7875
30 13550
Thanks

Similar Messages

  • How do I create a 1d array that takes a single calculation and insert the result into the first row and then the next calculation the next time the loop passes that point and puts the results in thsecond row and so on until the loop is exited.

    The attached file is work inprogress, with some dummy data sp that I can test it out without having to connect to equipment.
    The second tab is the one that I am having the problem with. the output array from the replace element appears to be starting at the index position of 1 rather than 0 but that is ok it is still show that the new data is placed in incrementing element locations. However the main array that I am trying to build that is suppose to take each new calculation and place it in the next index(row) does not ap
    pear to be working or at least I am not getting any indication on the inidcator.
    Basically what I am attempting to do is is gather some pulses from adevice for a minute, place the results for a calculation, so that it displays then do the same again the next minute, but put these result in the next row and so on until the specifiied time has expired and the loop exits. I need to have all results displayed and keep building the array(display until, the end of the test)Eventually I will have to include a min max section that displays the min and max values calculated, but that should be easy with the min max function.Actually I thought this should have been easy but, I gues I can not see the forest through the trees. Can any one help to slear this up for me.
    Attachments:
    regulation_tester_7_loops.vi ‏244 KB

    I didn't really have time to dig in and understand your program in depth,
    but I have a few tips for you that might things a bit easier:
    - You use local variables excessively which really complicates things. Try
    not to use them and it will make your life easier.
    - If you flowchart the design (very similar to a dataflow diagram, keep in
    mind!) you want to gather data, calculate a value from that data, store the
    calculation in an array, and loop while the time is in a certain range. So
    theres really not much need for a sequence as long as you get rid of the
    local variables (sequences also complicate things)
    - You loop again if timepassed+1 is still less than some constant. Rather
    than messing with locals it seems so much easier to use a shiftregister (if
    absolutely necessary) or in this case base it upon the number of iterations
    of the loop. In this case it looks like "time passed" is the same thing as
    the number of loop iterations, but I didn't check closely. There's an i
    terminal in your whileloop to read for the number of iterations.
    - After having simplified your design by eliminating unnecessary sequence
    and local variables, you should be able to draw out the labview diagram.
    Don't try to use the "insert into array" vis since theres no need. Each
    iteration of your loop calculates a number which goes into the next position
    of the array right? Pass your result outside the loop, and enable indexing
    on the terminal so Labview automatically generates the array for you. If
    your calculation is a function of previous data, then use a shift register
    to keep previous values around.
    I wish you luck. Post again if you have any questions. Without a more
    detailed understanding of your task at hand it's kind of hard to post actual
    code suggestions for you.
    -joey
    "nelsons" wrote in message
    news:[email protected]...
    > how do I create a 1d array that takes a single calculation and insert
    > the result into the first row and then the next calculation the next
    > time the loop passes that point and puts the results in thsecond row
    > and so on until the loop is exited.
    >
    > The attached file is work inprogress, with some dummy data sp that I
    > can test it out without having to connect to equipment.
    > The second tab is the one that I am having the problem with. the
    > output array from the replace element appears to be starting at the
    > index position of 1 rather than 0 but that is ok it is still show that
    > the new data is placed in incrementing element locations. However the
    > main array that I am trying to build that is suppose to take each new
    > calculation and place it in the next index(row) does not appear to be
    > working or at least I am not getting any indication on the inidcator.
    >
    > Basically what I am attempting to do is is gather some pulses from
    > adevice for a minute, place the results for a calculation, so that it
    > displays then do the same again the next minute, but put these result
    > in the next row and so on until the specifiied time has expired and
    > the loop exits. I need to have all results displayed and keep building
    > the array(display until, the end of the test)Eventually I will have to
    > include a min max section that displays the min and max values
    > calculated, but that should be easy with the min max function.Actually
    > I thought this should have been easy but, I gues I can not see the
    > forest through the trees. Can any one help to slear this up for me.

  • Please help me. I've just lost my iphone so I related to my backup contacts on icloud to get my contacts back. But my contacts only show at the first time and then they dissappeared, my contacts was empty. How can I see my contacts?

    Please help me. I've just lost my iphone so I related to my backup contacts on icloud to get my contacts back. But my contacts only show at the first time and then they dissappeared, my contacts was empty. How can I see my contacts?

    If they aren't on icloud.com they are no longer in iCloud.  If you don't have another backup, I'm afraid they're gone.

  • I plugged my iphone 4S into my computer for the first time and then my photos were replaced with the ones from my old iphone, how do i get them back?

    i plugged my iphone 4S into my computer for the first time and then my photos were replaced with the ones from my old iphone, how do i get them back?

    Try restoring from the backup created at the beginning of the sync process:
    Without connecting your phone, open iTunes, go to Preferences, on the Devices tab check "Prevent...from syncing automatically"
    Connect your phone, right-click on the name of your phone when it appears on the left sidebar in iTunes
    Select Restore from backup, choosing your most recent backup to restore from
    Disconnect your phone and confirm that your photos are back
    Go back to iTunes>Preferences>Devices and re-enable automatic syncing.

  • I would like to change of type of subscription to improve its level. Should I cancel the first one and then take another one ?

    hello
    I would like to change my type of subscription (adobe reader) to improve to get a higher level. Should I cancel the first one and then take another one ?
    thks
    cecile

    Hi Cecile,
    Please Contact Customer Care; an agent will be able to change your subscription from ExportPDF to Adobe PDF Pack, or an Acrobat subscription.
    Best,
    Sara

  • When I create a new project in iMovie and drop clips into it, it plays the first one and then quits right near the end of the second clip.  I have re-started my computer, tried a new project etc, and no luck, does anyone know how to fix this issue?

    When I create a new project in iMovie and drop clips into it, it plays the first one and then quits right near the end of the second clip.  I have re-started my computer, tried a new project etc, and no luck, does anyone know how to fix this issue?

    This is a part of the larger MacBook Pro connectivity issue. There are several related threads dealing with the MBP's networking problems. If your unit is suffering from this type of difficulty, good luck ... (or a long ethernet cable)
    (PS Everybody please make noise on this one so apple comes up with a solution.)
    < Edited by Host >

  • My 4630 printer only prints the first page and then cancels

    My 4630 printer only prints the first page and then cancels the rest of the document. I have to manually choose to print one page at a time. If I try to print a document, it prints the first page and then cancels printing the rest of it. It's driving me crazy. I just bought this printer and, other than that, it works fine. I tried the HOTFIX link that was attached to a previous link as well as other microsoft updates, however, am still having no luck.

    Hi @ImaniL,
    I believe I have something that could assist with your printing issue
    My colleague, @JERENDS, has created these instructions to help with issues similar to yours, and I believe his instructions will help resolve your printing issue!
    Let me know how things go, and if that doesn't fix it, I will certainly see what else I can find for you
    Please click “Accept as Solution ” if you feel my post resolved your issue, as it will help others find the solution faster
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    **MissTeriLynn**
    I work on behalf of HP

  • HT2954 My receive function on the email gets just the first email and then stops

    My receive function on the email gets just the first email and then stops, but the wheel keeps turning like it is looking.  What can I do to get it functioning again.  This program has been steady for several years so something in it is tweaked.  Other computers can access the account just fine.  If I shut down the mail program and start it up again it will get the same email and then go into the spinning mode again.  Is there a file I can delete to reset the account.  I have tried to re input the SMTP data but no luck.  Any Ideas?

    Not certain, but this can fix myriad Mail problems...
    Safe Boot from the HD, (holding Shift key down at bootup),  it will try to repair your Disk Directory while the spinning radian is happening, so let it go, run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, then move this folder & file to the Desktop.
    Move this Folder to the Desktop...
    /Users/YourUserName/Library/Caches/Mail/
    Move this file to the Desktop...
    /Users/YourUserName/Library/Mail/Envelope Index
    Reboot.
    If that doesn't do it and you can afford to redo all your Rules, try these & reboot...
    /Users/YourUserName/Library/Mail/MessageRules.plist
    /Users/YourUserName/Library/Mail/MessageRules.plist.backup
    Note, in 10.5 & up /Users/YourUserName/Library/Caches/Mail/ may or may not exist.

  • HT201320 Setting up mail only works the first time and then fails...

    Hello,
    I own a new iPad 4.
    Setting up my own mail accounts works great for the first time (I see new mails and I can sent mails), but the second time I open the Mail-App it complains about my mail settings.
    Mails are provided from my own domain. Using other mail clients I don't have issues.
    Setting is based on IMAP ssl/port 993 and ssl/578. iPad runs on IOS6.1.
    Do you have an idea why?
    Carsten

    iOS: Unable to send or receive email
    http://support.apple.com/kb/TS3899
    Can’t Send Emails on iPad – Troubleshooting Steps
    http://ipadhelp.com/ipad-help/ipad-cant-send-emails-troubleshooting-steps/
    Setting up and troubleshooting Mail
    http://www.apple.com/support/ipad/assistant/mail/
    iPad Mail
    http://www.apple.com/support/ipad/mail/
    Try this first - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.)
    Or this - Delete the account in Mail and then set it up again. Settings->Mail, Contacts, Calendars -> Accounts   Tap on the Account, then on the red button that says Remove Account.
     Cheers, Tom

  • I have a LaserJet 5L printer and I can't get it running properly under 10.5.8 while it works fine under 10.4.11. It only prints the first document and then shows the queue and prints slow like ****, it says so, but nothing printed after30 minuts.

    Hi.
    I have problems to get my Laser Jet 5L running properly under 10.5.8. I prints the first page/document and then it says1,36 % printed than printing but nothing happens. Under 10.4.11 everything works fine, sometimes I have to get the print jobs running again,but then it works.
    I have the Laser Jet 5L connected via USB to parallel.
    I am running a PowerBook G4 1,67 GHz and 2 GByte RAM.
    Best regards
    LasertJet5LApple

    Hello, since nobody has piped in yet...
    Safe Boot from the HD, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions.
    Safe Boot from the HD, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions.
    Any devices that previously appeared in your Printer List and Fax List will need to be added again after resetting the printing system.
    Resetting the printing system in Mac OS X 10.5.x
    1. To use the Reset Printing System feature in Mac OS X 10.5.x, follow these steps:
    2. Choose System Preferences from the Apple menu.
    3. Choose Print & Fax from the View menu.
    4. Control-click on list of printers on the left side of the window, then choose "Reset printing system" from the contextual menu. If you don't see a list of printers, Control-click on the text "Click + to add a printer or fax" and select "Reset printing system..." 
   
  As an alternative, if you currently have one or more printers listed, you can Option-click the "-" (Remove printer) button.
    http://support.apple.com/kb/ht1341
    Reboot.

  • Recordset per Message and then group again

    Hi All,
        Advise would be aprreciated for the following issue we are having on a productive environment.
        The interface gets a 3.4MB file from a FTP server, performa a mapping and then saves a new file to the receiver ftp server.
        Sometimes, we get an error because the xml message that the AE sends to the IE does not contains all the information as the flat file. It seems that it runs out of resources and does not finish the xml transformation process.
         I have read several post in the SDN and even sap notes, about using the Recordset per Message option. However, this way I get a lot of IE messages but, also a lot of files in the FTP server and I only need 1. Is there any way I can split them to avoid this issue and then put them all together again? I don't like the "Append option".
         Thanks and kind regards,
             David Encinas.

    Hi David,
       Using split you can achive your requirement.
       First create the Structure as per your Source Format.
      If your structure has different Sub structure , create for each substructure at the target end.
      do the massage mapping in message tab source one message type , target multiple messages...do the same thing in Interface mapping .(Here select source and targets occurence 1 only)
      create the Integration Process (BPM)..once receive the message you can validate the message using Switch statement , once condtion has satisfied then use the Transformation step (1:n) and then message use many Send steps.
    You can create multiple files with same locations.
      I had done same thing for my req....
    Reagads,
    Venu.

  • Get first value and then remove remaining in query output

    hi all,
    we have a query where we want to count the number of sales orders and show this count by created on month and salesperson.  trick is that sales orders have multiple line items so the same order can show in multiple months. 
    lets say order 1000 has 3 line items.  each item is for month 1,2 and 3 of 2009.  the report is showing as such:
    1.2009 1
    2.2009 1
    3.2009 1
    each value represents the same order number.  we only want to see 1.2009 and then 2 and 3 show nothing because the counting of the order should happen 1X.  so the first month it finds an order number in, it counts it for that month and if it finds the same order for a later month then don't count it.
    is there a way to accomplish this?
    thank you

    Hi there,
    If you simply want to create count on sales order, then in query designer, just create a calculated key figure in that use option of formula variable,
    create one new formula variable of processing type replacement path and assign that sales order number characteristic to reference characteristic.
    in next replacement path tab
    Replace variable with - Infoobject
    Replace with  - Attributes
    Attributes - characteristic reference.
    For calculated key figure use aggregation after option.
    Hope this will help you.
    Regards,
    Rajdeep.

  • HT204291 Airplay connected briefly for first time and then icon vanished from ipad

    I have been trying to locate Airplay on my new ipad3 This morning for the first time it appeared beside the volume control and I had brief success before the message appeared on the TV that Appletv was not connected. Both the ipad and and appletv are connected to the net and I have run photos and music through itunes happily. Now I can't find the Airplay icon and I have never been able to find it in Settings>General. Help

    I too have just had a similar problem once I upgraded to IOS6. I removed and then reconnected the wi-Fi to the Apple TV which reconnected the computer to Apple TV.  Still no airplay icon on IPad though.  So I reset the internet router which reconfigured all the wi-Fi connections and all appears to be working now. Hope this helps.

  • How to show the first page and then rest will be created in background

    Dear Friends,
    I am suffering from some seriouse issue of slow opening of report....
    I am using vs2005 and asp.net 2.0 and crXI R2 sp4,
    using oledb for getting data from ms sql server 2005.
    Now my one report called accounts ledger
    when i execute the report query it takes 1.03 mins for 515000 records..no issue with it ,
    when i execute the report from report desginer for 515000 records its taking 26 mins . It is generating all
    32000 pages.
    Now same report i run from my web based erp application it takes 30mins to execute 32000 pages now
    this is too much time it is taking and now our client is fedup of ussss..
    So is there any way that we can show First page at the earliest and rest of the pages willl be getting created in background? is it possible ?
    We have to give them the solution as sson as possible...
    can anyone suggest the diff ways to get out of this problem .......
    Please ur co operation will be appriciated....
    thansk

    Hi Mithun,
    Here are a few points related to performance issue. These might be helpful.
    The performance of a report is related to:
    External factors:
    1. The amount of time the database server takes to process the SQL query.
    ( Crystal Reports send the SQL query to the database, the database process it, and returns the data set to Crystal Reports. )
    2. Network traffics.
    3. Local computer processor speed.
    ( When Crystal Reports receives the data set, it generates a temp file to further filter the data when necessary, as well as to group, sort, process formulas, ... )
    4. The number of records returned
    ( If a SQL query returns a large number of records, it will take longer to format and display than if was returning a smaller data set.)
    Report design:
    1. Where is the Record Selection evaluated?
    Ensure your Record Selection Formula can be translated in SQL, so the data can be filter down on the server, otherwise the filtering will be done in a temp file on the local machine which will be much slower.
    They have many functions that cannot be translated in SQL because they may not have a standard SQL for it.
    For example, control structure like IF THEN ELSE cannot be translated into SQL. It will always be evaluated
    in Crystal Reports. But if you use an IF THEN ELSE on a parameter, it will convert the result of the condition to
    SQL, but as soon as uses database fileds in the conditions it will not be translated in SQL.
    2. How many subreports the report contains and in section section they are located.
    Minimise the number of subreports used, or avoid using subreports if possible because
    subreports are reports within a report, and if you have a subreport in a details section, and the report returns 100
    records, the subreport will be evaluated 100 times, so it will query the database 100 times. It is often the biggest
    factor why a report takes a long time to preview.
    3. How many records will be returned to the report.
    Large number of records will slow down the preview of the reports. Ensure you only returns the necessary data on the report, by creating a Record Selection Formula, or basing your report off a Stored Procedure, or a Command Object that only returns the desired data set.
    4. Do you use the special field "Page N of M", or "TotalPageCount"
    When the special field "Page N of M" or "TotalPageCount" is used on a report, it will have to generate each page
    of the report before it displays the first page, therfore it will take more time to display the first page of the report.
    If you want to improve the speed of a report, remove the special field "Page N of M" or "Total Page Count" or formula that uses the function "TotalPageCount". If those aren't use when you view a report it only format the page requested. It won't format the whole report.
    5. Link tables on indexed fields whenever possible.
    6. Remove unused tables, unused formulas, unused running totals from the report.
    7. Suppress unnecessary sections.
    8. For summaries, use conditional formulas instead of running totals when possible.
    9. Whenever possible, limit records through selection, not suppression.
    10. Use SQL expressions to convert fields to be used in record selection instead of using formula functions.
    For example, if you need to concatenate 2 fields together, instead of doing it in a formula, you can create a SQL Expression Field. It will concatenate the fields on the database server, instead of doing in Crystal Reports.
    SQL Expression Fields are added to the SELECT clause of the SQL Query send to the database.
    11. Using one command as the datasource can be faster if you returns only the desired data set. It can be faster if the SQL query written only return the desired data.
    12. Perform grouping on server
    This is only relevant if you only need to return the summary to your report but not the details. It will be faster as less data will be returned to the reports.
    Regards,
    Shweta

  • Bought album and it downloaded in iTunes but it only plays partial of first song and then skips to next song in album, help?

    Well I bought the Bring Me The Horizon album There Is A **** Believe Me I've Seen It, There Is A Heaven Let's Keep It A Secret on my iPhone and it synced to iTunes on my laptop. The entire album was downloading however when the first song was starting download it displayed an error message and I quickly pressed okay and disregarded it. The rest of the album resumed download and completed. I then went up to the download button next to the search input in the upper right hand corner and finished download for the rest of the song. When I went to listen to the album I was in a minute into the first song, "Crucify Me," and it skipped to the second song in the album, "It Never Ends." I tried playing it over and opening and re-opening iTunes but it still persists to skip the first song a minute in... so it appears to be a partial download. I mean, I have the album downloaded on my iPhone (this was the original site of purchase and download) but currently I am not in a state to do anything with that because my USB cable broke so my phone's been dead for the past few days and I'm waiting until tomorrow to get one with my father, I'm just a 14 year old girl afterall. I need a quick fix for this error and soon, preferably one without needing my iPhone because I want to listen to this album tonight and make sure it's all in order (and so I know what to do for future reference in case this happens again.) Please let me know your suggestions on resolving this issue. - Taylor
    P.S. I've inserted a picture of what my iTunes looks like just in case it might help, which I doubt, but it might. Also please don't judge the Blood On The Dance Floor albums... I went through a phase that involved **** music.

    Hi cruzansingerboi,
    Welcome to Apple Support Communities.
    It sounds like you've downloaded tracks on your iPhone and you want to download those same tracks on your PC. The article linked below will walk you through downloading previously purchased tracks on another device.
    Download past purchases
    http://support.apple.com/kb/HT2519
    You can also transfer the purchased content from your iOS device to your computer, as shown here:
    iTunes Store: Transfer purchases from your iOS device or iPod to a computer
    http://support.apple.com/kb/HT1848
    And, you may be interested in enabling Automatic Downloads of purchased content on your devices.
    iTunes Store: How to enable Automatic Downloads
    http://support.apple.com/kb/HT4539
    I hope this helps.
    -Jason

Maybe you are looking for

  • How does cycle count recommendation works.

    I setup my cycle count codes as well as assigning them to the item master, when I run cycle count recommendations there are lots of items need to be counted. Here are my questions 1.     Where do I go to enter the new counts? 2.     When I enter the

  • The iTunes Music Library file cannot be saved

    Ok, so without making any modifications (hardware or software) whatsoever- I come in from work, plop down to my computer, click on iTunes, and the music library has disappeared- I get the following error message: The iTunes Music Library file cannot

  • Mail downloaded headers but not content...

    ...and now won't download message headers either ... i can't receive new mail and i can't get to the content from any mail. i'm at a loss. here's what i did andexperienced today: 1) deleted 'old' mail account (hadn't pulled new mail since 11/2 9AM) 2

  • When I try to open a document it says "The document couldn't be opened"

    When I try to open a document it says "The document couldn't be opened" and it has a yellow triangle with an exclamation point in it.

  • Caching Mode, groups, address book

    GroupWise 2014 SP HP1 Hi, we experience problemes with groups in caching mode: while they show up correct with members in online mode and in WebAccess, they are empty in caching mode. I tried "Refresh", "Retrieve GW Address Book" and "Retrieve Entire