An SQL face question with answer _mssql

Source: Internet
Author: User
There are 1 sheets,

Wages table
-------------------------------------------
emp_id | Basic Salary | Job Seniority Wages |
-------------------------------------------
1 | 1.00 | 1.00 |
-------------------------------------------
2 | 1.00 | 2.00 |
-------------------------------------------
3 | 1.00 | 3.00 |
-------------------------------------------
4 | 1.00 | 4.00 |
-------------------------------------------
.........

Please use "One sentence combination query" from the above table to query the salary statistics, and request the retrieved content format as follows:

-----------------------------------------------------------------
emp_id | Basic Salary | Job Seniority Wages | Total | Position
------------------------------------------------------------------
1 | 1.00 | 1.00 |2.00 | X
------------------------------------------------------------------
2 | 1.00 | 2.00 |3.00 | Y
------------------------------------------------------------------
3 | 1.00 | 3.00 |4.00 |.
------------------------------------------------------------------
4 | 1.00 | 4.00 |5.00 |.
------------------------------------------------------------------

Reply:
Copy Code code as follows:

begin tran  
Create table wages (Emp_id  bigint not null primary key, basic salary  money,  job seniority wages  money)   
Go   
Insert into wages (emp_id, base salary, job seniority wages) VALUES (1,1.00,1.00)   
insert  Into wages (emp_id, basic salary, job seniority wages) VALUES (2,1.00,2.00)   
Insert into wages (emp_id, base salary, Job seniority wages values (3,1.00,3.00)   
Insert into wages (emp_id, base salary, job seniority wages) VALUES (4,1.00,4.00)    
if @ @error >0 rollback else commit tran  
select emp_id , basic salary, job seniority wages, base salary + job seniority wages  as  Total, row_number ()  over (order by  base salary + job seniority wages)  as  rank  from Wages order by  Total   
--drop table wages

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.