UNION ALL 命令和 UNION 命令几乎是等效的,不过 UNION ALL 命令会列出所有的值。
'分发' AS `operatype`,这种写法是为了把该列内容写死(保证与下面的select的列数相同)
CONCAT 固定字符串
IFNULL() 函数用于判断第一个表达式是否为 NULL,如果为 NULL 则返回第二个参数的值,如果不为 NULL 则返回第一个参数的值
SELECT
`d`.`contract_number` AS `contractno`,
`d`.`customer_id` AS `fieldno`,
'分发' AS `operatype`,
`c`.`customer_name` AS `customer_name`,
concat( '从 ', `u`.`true_name`, ' 流转到 ', `b`.`true_name` ) AS `baseinfo`,
`u`.`true_name` AS `staffname`,
`a`.`created_at` AS `dtime`,
`b`.`true_name` AS `recive_name`,
'信息分派' AS `memo`
FROM
`crm_customer_assignment` `a`
LEFT JOIN &