How to insert a zero when COUNT returns null? MySQL
I have the following in a trigger and want it to insert zero when NULL is
returned. I have read various posts here on Stackoverflow and other sites
over the past two days but have been unable to achieve what I want...and
am afraid that it may not be possible...? This query returns all users
from MCVMoodle.mdl_facetoface_signups.userid with count values for grade
(that meet the WHERE conditions) with count values of 1 or more but
nothing for 0/null. I understand the difficulty of working with no
result/null but is there anyway to get a zero inserted when the count is
0/null?
INSERT INTO MCVMoodle.mdl_user_info_data_f2fskipcount (userid, fieldid,
datab)
SELECT MCVMoodle.mdl_facetoface_signups.userid as 'userid', 4 as 'fieldid',
COUNT(MCVMoodle.mdl_facetoface_signups_status.grade) as 'datab'
FROM
MCVMoodle.mdl_facetoface_signups
LEFT JOIN
MCVMoodle.mdl_facetoface_signups_status on
MCVMoodle.mdl_facetoface_signups.id =
MCVMoodle.mdl_facetoface_signups_status.signupid
WHERE
MCVMoodle.mdl_facetoface_signups_status.statuscode = 80
AND MCVMoodle.mdl_facetoface_signups_status.superceded = 0
AND MCVMoodle.mdl_facetoface_signups_status.grade = 0
GROUP BY
MCVMoodle.mdl_facetoface_signups.userid;
No comments:
Post a Comment