我怎样才能笨
问题描述:
查询这这就是我想要的:我怎样才能笨
SELECT DISTINCT first_name,last_name
FROM employees e
INNER JOIN salaries s ON e.emp_no = s.emp_no
WHERE e.birth_date > '1963-01-01'
AND s.salary>150000
我已经试过这一点,我得到了我想要的名字,但也是一个额外的12名。有些事情是错的。
$this->db->distinct();
$this->db->select('first_name, last_name');
$this->db->from('employees');
$this->db->join('salaries s', 'e.emp_no = s.emp_no', 'inner');
$this->db->where('e.birth_date > 1963-01-01');
$this->db->where('s.salary > 150000');
$result = $this->db->get();
答
在where子句中,经营者应在第一个参数被输入到与第二个参数的值进行比较。
$this->db->where('e.birth_date >', 1963-01-01);
$this->db->where('s.salary >', 150000');
答
我添加了一个评论,但我会添加它作为一个建议answer.You没有别名employees
在$this->db->from('employees');
添加电子员工后,像你这样的薪金秒。
$this->db->distinct();
$this->db->select('first_name, last_name');
$this->db->from('employees e');
$this->db->join('salaries s', 'e.emp_no = s.emp_no', 'inner');
$this->db->where('e.birth_date > 1963-01-01');
$this->db->where('s.salary > 150000');
$result = $this->db->get();
编辑:在where子句中没有引用的日期字符串。尝试更新语句以引用该字符串,或者将其作为第二个参数传递。
$this->db->where('e.birth_date > "1963-01-01"');
或
$this->db->where('e.birth_date >', '1963-01-01');
我假定这是在你的数据库中的日期栏正确的格式掩码。
答
如果活动记录让你感到困惑,那很容易。你可以简单的使用查询功能
$query = "SELECT
DISTINCT first_name,
last_name
FROM employees e
INNER JOIN salaries s ON e.emp_no = s.emp_no
WHERE e.birth_date > '1963-01-01'
AND s.salary>150000";
$this->db->query($query);
您没有在'$ this-> db->中从'('employees')别名'employees';'在像您这样的员工为'slaries s'工作之后添加'e'。 – Wolf 2013-04-25 16:34:30