简体   繁体   English

使用WHERE子句在SQL中输入数字的条件

[英]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. 我是SQL的新手,我不确定我是否对尝试使用的问题正确使用条件。

"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." “生成一个结果集,其中显示项目名称,项目开始日期,项目结束日期,员工名字,员工姓氏,员工头衔和员工小时工资。仅包括同时满足两个条件的记录:(1)项目开始日期于;或在2018年7月1日之后;和(2)员工的时薪大于或等于25美元。按项目名称排序。”

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. 我有一个完整的SELECT语句,我只想知道我是否正确使用了条件,如果代码完全正确。 I am not able to test it as I was not given the table contents. 由于无法获得表内容,因此我无法对其进行测试。

Here is the table: https://imgur.com/a/sr8EHCn 表格如下: 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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