[英]Inner Join Query on 3 Tables
I don't know what is wrong here. 我不知道这是怎么回事。 I am running a query with a multiple join of 3 tables, the query below works perfectly... Giving me the employee details, his age, if he requires the certificate and gives me info regarding the certificates expiry date, also puts a "-" in the next field if a certificate is not required - and as I said, this works like a charm...
我正在运行一个带有3个表的多个联接的查询,下面的查询非常正常...给我雇员的详细信息,他的年龄,如果他需要证书并给我有关证书到期日期的信息,还请输入“- “如果不需要证书,请在下一个字段中输入-就像我说的那样,它的作用就像是一种魅力……
SELECT
`employee`.*,
date_format(now(), '%Y') - date_format(`empl_dob`, '%Y') -
(date_format(now(), '00-%m-%d') < date_format(`empl_dob`, '00-%m-%d')) AS age,
`certs`.`cert_medical_restrict`,
IF( `jobtitle`.`jt_medical`='n/a', `jobtitle`.`jt_medical`,
IF( `certs`.`cert_medical` = 0, 'No Cert',
IF( (DATEDIFF((DATE_ADD(`certs`.`cert_medical`, INTERVAL 365 DAY)),CURDATE())) < 1, 'X',
IF( (DATEDIFF((DATE_ADD(`certs`.`cert_medical`, INTERVAL 365 DAY)),CURDATE())) < 30, 'ES', 'ok')))
) AS medical,
IF( `jobtitle`.`jt_medical`='n/a', '-',
IF( `certs`.`cert_medical` = 0, '-', (DATEDIFF((DATE_ADD(`certs`.`cert_medical`, INTERVAL 365 DAY)),CURDATE())))) AS medicalx
FROM `employee`
JOIN `jobtitle`
ON `employee`.`jobtitle_id` = `jobtitle`.`jobtitle_id`
JOIN `certs`
ON `certs`.`empl_idno` = `employee`.`empl_idno`
WHERE `employee`.`empl_no` = '10517602'
...But for my next query, I need to display the actual expiry date of the certificate, the queries look very much the same, but without the extra IF statements... ...但是对于我的下一个查询,我需要显示证书的实际到期日期,查询看起来几乎相同,但是没有多余的IF语句...
SELECT
`employee`.*,
date_format(now(), '%Y') - date_format(`empl_dob`, '%Y') -
(date_format(now(), '00-%m-%d') < date_format(`empl_dob`, '00-%m-%d')) AS age,
`certs`.`cert_medical_restrict`,
IF( `jobtitle`.`jt_medical`='n/a', `jobtitle`.`jt_medical`,
IF( `certs`.`cert_medical` = 0, 'No Cert', (DATE_ADD(`certs`.`cert_medical`, INTERVAL 365 DAY)))) AS medical,
IF( `jobtitle`.`jt_medical`='n/a', '-',
IF( `certs`.`cert_medical` = 0, '-', (DATEDIFF((DATE_ADD(`certs`.`cert_medical`, INTERVAL 365 DAY)),CURDATE())))) AS medicalx
FROM `employee`
JOIN `jobtitle`
ON `employee`.`jobtitle_id` = `jobtitle`.`jobtitle_id`
JOIN `certs`
ON `certs`.`empl_idno` = `employee`.`empl_idno`
WHERE `employee`.`empl_no` = '10517602'
Now I get this error "Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation 'if' " I cannot get my head around it, I have checked to see if the three tables differ from each other, but all are set to "latin_swedish_ci" 现在,我收到此错误“操作'if'的排序规则(latin1_swedish_ci,IMPLICIT)和(utf8mb4_general_ci,COERCIBLE)的非法混合,“我无法理解,我检查了三个表是否彼此不同,但是全部设置为“ latin_swedish_ci”
What am I doing wrong here? 我在这里做错了什么? Any help would be appreciated - thanx
任何帮助将不胜感激-thanx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.