For the MONEY and to break on a column SQL query

Hello

I have a situation where the data in the table are as below

AA

BB

1

FG

1

FG

1

FG

2

SS

1

FG

I need to write a sql query that would give output like below. Basically, it must break BB of the column and the value of the sum up to what it breaks.

AA

BB

3

FG

2

SS

1

FG

Please suggest.

Thank you

Shankar

Hello

770914 wrote:

Hello

I have a situation where the data in the table are as below

AA

BB

1

FG

1

FG

1

FG

2

SS

1

FG

I need to write a sql query that would give output like below. Basically, it must break BB of the column and the value of the sum up to what it breaks.

AA

BB

3

FG

2

SS

1

FG

Please suggest.

Thank you

Shankar

Remember, there is no order integrated to the rows in a table.  The table you have posted is exactly the same as:

AA bb

--    --

1 FG

1 FG

2 SS

1 FG

1 FG

and both are exactly the same as:

AA bb

--    --

2 SS

1 FG

1 FG

1 FG

1 FG

If you use words like 'first', 'previous' or 'row' when it comes to lines, then we must define what these words mean.  This is usually done by making reference to a column in the table.  For example, if you had a column called r_num, like this:

AA bb r_num

--    --    -----

1 FG 1

1 FG 2

1 FG 9

2 SS 10

1 FG 10.5

Then, it would be wise to say things like 'the table starts with 3 lines consecutive "FG", followed by "SS".  After that there is another "FG", which is the last line in the table, WHEN TRIE BY R_NUM.   If the part about "WHEN SORTED BY R_NUM" is not known, the words 'begins '. "consecutive", 'followed', 'after' and 'last' have no meaning.

If (and only if) you have somehting like r_num in your table. Then you can get the resutls you want like this:

WITH got_group_num AS

(

SELECT aa, bb, r_num

ROW_NUMBER () OVER (ORDER BY r_num)

-ROW_NUMBER () OVER (PARTITION BY bb

ORDER BY r_num

) AS group_num

FROM table_x

)

SELECT SUM (aa) AS total_aa

,         bb

OF got_group_num

GROUP BY bb

group_num

ORDER OF MIN (r_num)

;

Tags: Database

Similar Questions

  • Why the forums seem to disappear?  You try to avoid the real issues?  You're just in it for the money and not to advance creativity.

    So, I asked a question, had a normal BS corporate scripted answer, then tried to track and, wow, no surprise in this day of Trump and other fascists (aka Adobe), could not ask a follow-up question.  Is it a real community or just a false sense of participation provided for by Orwell?    How do real people, real creations, the problems (and there ARE real problems with this stupid CC model)?

    What is the procedure for tracking issues, troubleshooting, etc.?  Or y at - it no, and does not care about Adobe?    BE SPECIFIC.     GIVE A CLEAR PROCESS, VERY VERY CLEAR, STEP BY STEP TO FOLLOW OR JUST ADMIT THAT YOU WANT TO SKIP THIS QUESTION AND THE BEAK OF USELESS PLATITUDES.

    You posted this at 08:13 if ask you questions about the MESSAGE, no forum, where you posted at 8:17 in when the student teacher rate goes up to 50% at the end of the first year, which is the motivation to continue?  Customer loyalty is not rewarded but punished. ?

    Look at past Messages

    Click on your Avatar image to the left of your message

    Click the option for the activity

    User manual for the community of Adobe (forums) https://forums.adobe.com/docs/DOC-4714

    -or http://docs.jivesoftware.com/jive/7.0/community_user/index.jsp

    The answer to your other question IS clear and concise... Adobe, like many other businesses, offering a discount to new buyers... and at the end of the discount period, the price goes up to the usual amount

    If you don't like that, very well... but Adobe isn't the only company that has further reductions of the buyer

  • Double charged for the service and support will not help!  Can you?

    Anyone know the secret to get a real person on the phone at Adobe?  These cat overseas representatives are not cut it!  I have a detailed transcript of a chat where the rep has no idea and can't even articulate their responses well enough to be called support. My problem is simple:

    Last month, Adobe somehow has not received my automatic membership via PayPal payment, even if the PayPal transaction has been completed, and the funds have been removed and delivered (I have documentation that Adobe don't want to watch).

    I used the support available to me - a poor attempt at a service of cat - nothing works.  The representative was informed of the situation and proceeded to charge me for the service once again, even though I told them I had already been charged, and it was a mistake on their part.  Now I have an another $49.99 charge on my account.  So that re - activate my subscription, it wasn't what I asked.  When I contacted PayPal about this, their response was to cancel my subscription, completely, but still no refund my second count (they also have a system of foreign aid, under normal)...  Now, I'm in the 'warning' of 30 days period before my service is completely turned off and not sure if I want to trust Adobe to my money, once again.  I contacted my bank - that should be a last resort, but I guess that is where I am, now.  They are willing to work with me, because I can pick up the phone and explain the situation to them.  Why I can't do this with Adobe?

    My last option is to take advantage of free legal assistance for my company and sue Adobe for $49.99, which seems silly, until you realize that it's free, and Disney has AMAZING lawyers at our disposal.  Is this really necessary?  Why am I put through so much aggravation due to the error of Adobe?  If I return, I would expect compensation for my trouble.  At least a few months of free service for the overload and my months of unrest.  Otherwise, affinity looking really tempting...

    Hello

    Please see Contact Support FAQ: impossible to reach support via the link "Contact us"

    Hope that helps!

    Kind regards

    Sheena

  • How to use GREP to apply the character style just for the first and the second line of the paragraph?

    as the title, I just want to ask how to apply the style of character just for the 1st and 2nd line of the paragraph. Help me pls, tks!

    Can you show the screen shot with the invisible market, looks like you feedback after each line.

    So, something like this would work where I have a return forced for the linebreak (shift + return). The example on the right does not work because the line break is a return:

  • How can I add a separate apple for the iphone and ipad wife id

    How can I add a separate apple for the iphone and ipad wife id

    Hi, are the measures already implemented? If they are, you need to configure them again and establish a Apple ID at this time.

    Apple ID - Support official Apple

  • How to get back my data for the health and the watch Apps once I've restored my phone?

    How to get back my data for the health and the watch Apps once I've restored my phone?

    From the backup, you're going to be restoration.

    If you back up to iTunes, make sure that it is an encrypted backup.

  • Is it possible to play different sounds for the emails and instant messages?

    Hello

    I was wondering if it was possible to play different sounds for the emails and instant messages. I use Thunderbird quite often with emails and instant messages imported from Gtalk.

    I think it would be very convenient to be able to distinguish the two sounds, because they do not involve the same things.

    Thank you very much.

    Olivier Hubert.

    There are only six modules of cat, three of them are on notifications. Choose the one you think will do the job for you. https://addons.Mozilla.org/en-us/Thunderbird/Extensions/chat/?sort=popular

  • And how does one remove Christmas lights that have been offered as a decoration for the top and shifts of the screen. They tend to hide the navigation bar.

    And how one removes the Christmas lights that have been offered as a decoration for the top and bottom of the screen. They tend to hide the navigation bar. Several days ago Firefox gave the 'dress-up' in a message.

    It seems that https://addons.mozilla.org/firefox/addon/christmas-lights/ is added as an extension, but is categorized as a character (lightweight themes). Go to tools > Modules then check extensions and themes, and then uninstall it.

    Now that the status bar is now the toolbar addons that I see those that are listed are all personas and they do not affect the toolbar addons you would also find a theme, and think that it must be very confused now that I no longer able to filter topics with a Google addons research - phooey.

    Extensions can be identified with intitle: Add - ons and have changed my research of extension add-ons accordingly.

  • my external cd will not appear in the finder or on the desktop.  I went into preferences for the finder and intended to show the CD, I can load a blank cd and iTunes says and I burn on it then the cd will appear on the desktop.

    I don't see my external cd in the finder under devices, I can load a blank cd and iTunes says it's white and I can burn songs, then the cd icon appears on the desktop, went into preferences for the finder and ticked the box show the cd.  Help please?  CD has been disconnected and placed back started loading but no show, iMac says he had an attached cd when I search.

    CD/DVD players don't appear that a disk is inserted. It's normal.

  • Sometimes I don't get and the vibrations or sounds for the text and incoming calls

    Hello

    I have phone 6

    Sometimes I'm not vibrations and sounds for the text and incoming calls

    I went to all the sound settings

    Thank you

    Is there a moon icon in the top right?

  • App for the time and payroll sheet calculations

    My daughter in hospitality makes work so much split and travel on a Saturday and Sunday. I am looking for an application that we can punch in his hours for the week and be able to do the calculation of salary based on the appropriate hourly rate so that we can keep control of when it is paid as it's done correctly. Essentially, I'm lookin for an app connects timesheet information to the payroll data. Such an application exists and if so can anyone recommend one? Happy to pay for an if need be.

    Hello alissah6,

    Numbers from Apple is what I would recommend as far as doing calculations with a simple formula. You can learn more about this here.

    The application costs $14.99, however it is packed and has more than 30 models - not to mention, you can also create your own if necessary.

    I would check it out certainly if I'm looking for a few terms related to pay calculation in the App Store.

    Thank you

    James.

  • Satellite 1000-Z2: I need a driver for the display and the LAN

    Hello

    I reformatted my laptop S1000-Z2, and I have a real problem trying to find all the information about this model!

    Basically, I need a driver for the display and the LAN?

    Best regards

    Austin.

    What operating system do you use?
    If you use XP, you will not find the network on the site recommended driver driver!
    I can't give you advice where to find such driver because I don t know what the LAN card is installed in your oldie.

    But why you n t check yourself? Try to know what the LAN card you use and googel a bit for compatible applications ;)

  • Is there an online community which deals with promotion within the Fed/DoD IT apple? Currently, I work for the NAVY and a nightmare HP NMCI. Thank you.

    It was more of a general question asking management and online community eventually the federal and/or DoD workers who might be unhappy with the current situation of technology of the federal workforce and so therefore could discuss, share and work information to try to improve this situation. Thank you.

    edhazelwood wrote:

    It was more of a general question asking management and online community eventually the federal and/or DoD workers who might be unhappy with the current situation of technology of the federal workforce and so therefore could discuss, share and work information to try to improve this situation. Thank you.

    «I currently work for the NAVY and a nightmare HP NMCI.»

    If you are now looking for a Mac NMCI nightmare? Evolution towards a Mac environment will do nothing to improve the NMCI environment.

    Why don't do you a Google search or speak to your personal COMPUTING support to discuss your NMCI questions? These forums are to help users of the Apple/Mac product with Apple/Mac product questions.

  • How can I disable the Mappoint 2006 for the installation and the reactivation on new computer

    How can I disable the MapPoint 2006 for the installation and the reactivation on new computer

    This forum is for posting comments on the web site of Microsoft Answers, only not to ask questions of Mappoint.

    Mappoint forum is here: http://social.microsoft.com/Forums/en-US/streetsandtrips/threads

  • Add Hardware Wizard asking to install drivers for the keyboard and mouse.

    Original title: Assistant material is locking up my computer...

    Assistant adding hardware asks me to install the drivers for the keyboard and mouse however, it locks the computer and I can't type or click on anything whatsoever.  If I go into the set-up menu to reboot, the keyboard works fine.  How can I stop this from happening?

    I was able to run an analysis of the system through the establishment and who has solved the problem of mouse enough to do what else to do to solve the problem.

    Thank you for your reply and your help.

Maybe you are looking for