简体   繁体   中英

SQL Finding Hourly Wage From Annual Salary And Hourly Wage Values

Normally finding hourly wage is simple SQL statement. But, as seen with the data below, the SalaryWage column has values that are stored as yearly wage and hourly wage. I need to sort it by who has the highest hourly wage. Somehow you need to take the SalaryWage column that has the annual wages listed and convert just those values to hourly wage. Then sort via the hourly wage.

This is what I have so far so you can see the names of my tables and such.

select EMPLOYEEID, LASTNAME || ', ' || FIRSTNAME As Employee_Name, HIREDATE, SALARYWAGE
from EMPLOYEE;

Download the Excel File below http://www.filedropper.com/book1_6

EmployeeID    Employee_Name    HIREDATE    SALARYWAGE
100001        Manaugh, Jim     15-Mar-09   75500
100101        Rosner, Joanne   4-Apr-09    16.3
100103        Bush, Rita       30-Jan-09   85800

A column based on a CASE expression will make easy work of the data in its present condition, and it can also be referenced in an ORDER BY at the same level, so you don't need to push the logic down into a sub-select. That said, I share @Clockwork-Muse's concern about the sanity of using a single column to store either of two different pay types (yearly vs. hourly). I hope the original question is part of a transitory effort to isolate and convert the salary data to use the same pay period.

SELECT EMPLOYEEID, LASTNAME || ', ' || FIRSTNAME As Employee_Name,  
HIREDATE, SALARYWAGE,
CASE WHEN (SALARYWAGE > 1000) THEN (salarywage / 2000) 
    ELSE salarywage END     
AS hourlywage
FROM EMPLOYEE ORDER BY hourlywage DESC;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM