我正在使用MySql,请参阅 http://postimg.org/image/waso0lsnf/ 查看我的表格结构。
我想要提取enduser_to_department = Y
department_to_enduser = Y
以及department_id.
。
对于相同的SELECT `departments`.`department_id`, `departments`.`department`
FROM `custom_forms_departments` , `departments`
WHERE departments.department_id = custom_forms_departments.department_id
AND (`custom_forms_departments`.`enduser_to_department` = 'Y'
OR `custom_forms_departments`.`department_to_enduser` = 'Y')
GROUP BY `departments`.`department_id`
ORDER BY departments.department_id DESC
我尝试过以下方式,但它适用于单行。
:inherited-members:
http://postimg.org/image/waso0lsnf/
修改:从网址添加图片。
答案 0 :(得分:0)
在where子句中,您可以指定条件
enduser_to_departmen ='Y'和department_to_enduser ='Y'
而不是group by u可以使用distinct
答案 1 :(得分:0)
试试这个:
SELECT `department_id`
FROM `custom_forms_departments`
WHERE `enduser_to_department` = 'Y'
AND `department_to_enduser` = 'Y'
GROUP BY `departments`.`department_id`
ORDER BY departments.department_id DESC
编辑:现在不加入。
我刚刚为OR
更改了AND
,因为您希望它们都是' Y' ,并更改了联接。
答案 2 :(得分:0)
希望这能解决你的问题
SELECT departments
。department_id
,departments
。department
来自custom_forms_departments
左连接departments
WHERE departments.department_id = custom_forms_departments.department_id
AND(custom_forms_departments
。enduser_to_department
='Y'
或custom_forms_departments
。department_to_enduser
='Y')
ORDER BY departments.department_id DESC