ifnull()函数,join关联表时,将值为null的字段设置为0

2020-03-08

ifnull()函数;判断字段的值是否为null,为null时,值等于ifnull的第二个参数

SELECT
	`o`.`id` AS `oid`,
	`o`.`xmec` AS `mech_id`,
	`o`.`receive_time` AS `receive_time`,
	`o`.`xstate` AS `xstate`,
	`a`.`busnumber` AS `busnumber`,
	`a`.`ptid` AS `ptid`,
	`a`.`apply_type` AS `apply_type`,
	`a`.`quecheck` AS `quecheck`,
	`a`.`check_shen_time` AS `check_shen_time`,
	`a`.`wtime` AS `wtime`,
	ifnull( `c`.`issued`, 0 ) AS `issued`,
	`c`.`publish_time` AS `publish_time` 
FROM
	((
		`ce_order` `o`
		 JOIN `ce_apply` `a` ON ((
			`a`.`orderid` = `o`.`id` 
		 )))
		 LEFT JOIN `ce_certif` `c` ON ((
		     `a`.`id` = `c`.`apply_id` 
	)))
{/if}