这是我的疑问:
SELECT
employee.name,
employee.type,
employee.rate,
work.overtime,
work.leaves,
work.ticket
FROM employee
LEFT JOIN work ON employee.name = work.name
WHERE work.date BETWEEN :date1 and :date2
HAVING employee.type = :type_emp
但它没有用。我想获取特定类型的员工列表,他们的工作状态应该从日期1到日期2显示。
我该怎么做?
答案 0 :(得分:2)
你试过了吗?
SELECT
`employee`.name,
`employee`.type,
`employee`.rate,
`work`.overtime,
`work`.leaves,
`work`.ticket
FROM `employee`
LEFT JOIN `work` ON `employee`.name = `work`.name
AND (`work`.date BETWEEN :date1 AND :date2)
WHERE `employee`.type = :type_emp
答案 1 :(得分:0)
SELECT employee.name, employee.type, employee.rate, work.overtime, work.leaves, work.ticket
FROM employee
LEFT JOIN work on employee.name=work.name
AND work.date between :date1 and :date2
WHERE employee.type=:type_emp
原版
有两个问题还有另一个潜在的问题,因为它不是过滤日期范围的最佳方法,而是以下方法通常更好但是:date2变成了现在使用的“第二天”。
SELECT employee.name, employee.type, employee.rate, work.overtime, work.leaves, work.ticket
FROM employee
LEFT JOIN work on employee.name=work.name
AND work.date >= :date1 AND work.date < :date2
WHERE employee.type=:type_emp
答案 2 :(得分:0)
将' '替换为'和'(不带引号)
答案 3 :(得分:0)
使用AND运算符调用where子句中的两个条件。试试以下
SELECT employee.name, employee.type,
employee.rate, work.overtime, work.leaves, work.ticket
FROM employee LEFT JOIN work
ON employee.name=work.name
WHERE employee.type=:type_emp AND
work.date between :date1 and :date2