sql语句 请大神帮忙看下 哪错了。
我用的是zendframework 写在了模型层里
$sql = 'SELECT `crm_order`.`oid`,
`crm_order`.`title`,
`crm_order`.`status`,
`crm_order`.`content`,
`crm_order`.`uid`,
`crm_order`.`createtime`,
`crm_order`.`orderstatus`,
`crm_order`.`department`,
`crm_order`.`type`,
`crm_ordertype`.`ot_name`,
`crm_user`.`name` FROM `crm_order`
LEFT JOIN `crm_ordertype` ON crm_order.type = crm_ordertype.ot_id
LEFT JOIN `crm_user` ON crm_user.uid = crm_order.uid ';
// where `crm_order`.`oid` =48 where aa = :bb
return $db->fetchAll($sql);
如果我还想加入表crm_department 中的字段part_name 然后显示crm_order中的crm_department 该怎么写呢?我总是写错。求指导。。,。 mysql?
[解决办法]
问题是我看不懂你的描述,而且这里是sqlserver专区哦
[解决办法]
?
$sql = '
SELECT
`crm_order`.`oid`,
`crm_order`.`title`,
`crm_order`.`status`,
`crm_order`.`content`,
`crm_order`.`uid`,
`crm_order`.`createtime`,
`crm_order`.`orderstatus`,
`crm_order`.`department`,
`crm_order`.`type`,
`crm_ordertype`.`ot_name`,
`crm_user`.`name`,
`crm_order`.`name`,
`crm_department`.`crm_department`
FROM `crm_order`
LEFT JOIN `crm_ordertype` ON crm_order.type = crm_ordertype.ot_id
LEFT JOIN `crm_user` ON crm_user.uid = crm_order.uid
INNER JOIN `crm_department` ON crm_user.departmentid = crm_department.id ';
return $db->fetchAll($sql);
$sql = '
SELECT
`crm_order`.`oid`,
`crm_order`.`title`,
`crm_order`.`status`,
`crm_order`.`content`,
`crm_order`.`uid`,
`crm_order`.`createtime`,
`crm_order`.`orderstatus`,
`crm_order`.`department`,
`crm_order`.`type`,
`crm_ordertype`.`ot_name`,
`crm_user`.`name`,
`crm_order`.`name`,
`crm_department`.`part_name`
FROM `crm_order`
LEFT JOIN `crm_ordertype` ON crm_order.type = crm_ordertype.ot_id
LEFT JOIN `crm_user` ON crm_user.uid = crm_order.uid
LEFT JOIN `crm_department` ON 哪个表的.关联字段 = crm_department.关联字段';
return $db->fetchAll($sql);