简体   繁体   中英

Inputting conditions for numbers in SQL using WHERE clause

I am new to SQL and I am not sure if I am using conditions correctly for a question I am trying to answer.

"Produce a result set showing project name, project start date, project end date, employee first name, employee last name, employee title, and employee hourly wage. Include only records that satisfy both of two conditions: (1) project start date on or after July 1, 2018; and (2) employee hourly wage greater than or equal to $25. Sort by project name."

I have a full on SELECT statement, I just would like to know if I am using the conditions correctly, if the code is correct at all. I am not able to test it as I was not given the table contents.

Here is the table: https://imgur.com/a/sr8EHCn

SELECT projectName, projectStartDate, projectEndDate, empFirstName, empLastName, empTitle, empHourlyWage
FROM project, employee
WHERE projectStartDate >= TO_DATE(‘2018-07-01’,’yyyy-mm-dd’)
AND empHourlyWage >= 25.00
ORDER BY projectName;

You were close. Your big mistake was that you forgot to join the tables.

Besides that, when a query mentions multiple tables it's better to prefix each column with the table it belongs to -- or an alias as in this case -- to avoid any confusion.

Your query should look like:

SELECT
  p.projectName, 
  p.projectStartDate, 
  p.projectEndDate, 
  e.empFirstName, 
  e.empLastName, 
  e.empTitle, 
  e.empHourlyWage
FROM project p
JOIN project2emp pe on pe.projectID = p.projectID
JOIN employee e on e.empID = pe.empID
WHERE p.projectStartDate >= TO_DATE('2018-07-01', 'YYYY-MM-DD')
AND e.empHourlyWage >= 25.00
ORDER BY p.projectName

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