Grouping statistics-SQL interview questions

Source: Internet
Author: User
An SQL interview question is very simple. Year salary
----------------------
2000 1000
2001 2000
2002 3000
2003 4000 here is a company table. An SQL statement queries the salary of the following result year.
----------------------
2000 1000
2001 3000
2002 6000
2003 10000
 
-- Author: [DBA] Small seven set nocount ondeclare @ t table (Year int, salary INT) insert into @ t select, Union allselect, Union allselect select * From @ tselect. year, sum (B. salary) as salary from @ t a, @ t B where. year> = B. year group by. select Year of year, (select sum (salary) from @ t where year <=. year) salary from @ t a -- another statement provided by M, haha set nocount off year salary ----------- 2000 10002001 20002002 30002003 4000 salary in March ----------------- 2000 10002001 30002002 60002003 10000

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.