我有一个带有以下列/值的mysql表
d1 d2 d3 d4 d5
10 12 9 2 6
我无法弄清楚如何获取匹配值的列名...如果匹配的值为d1
,则查询应返回10
。我只是想要为匹配的值
这是订单列表查询..此查询的问题是它返回所有部门的所有挂单。但如果我添加AND stage
='d1'我会工作
我只是不知道如何从我演示的布局中获得'd1'或'd2''d3'
SELECT `phoenix_so`.`id`, `stage`, `so_number`, `service` AS service_id, `cid`, `uid`, `pec`, `customer_name`, `phoenix_so_service`.`name` AS service, `location`, `phoenix_so_priority`.`name` AS pri, `phoenix_so_priority`.`css_class`, `phoenix_so_type`.`name` as type, `phoenix_so_type`.`css_class` AS type_css
FROM (`phoenix_so`)
LEFT JOIN `phoenix_so_service` ON `phoenix_so`.`service` = `phoenix_so_service`.`id`
LEFT JOIN `phoenix_so_priority` ON `phoenix_so`.`priority` = `phoenix_so_priority`.`id`
LEFT JOIN `phoenix_so_type` ON `phoenix_so`.`type` = `phoenix_so_type`.`id`
LEFT JOIN `phoenix_so_roadmap` ON `phoenix_so`.`service` = `phoenix_so_roadmap`.`service_id`
WHERE `inv_access_cdate` = "0000-00-00"