0

我在 mysql 查询中使用 FIND_IN_SET 此查询将给出电子邮件 ID 在 from_email 或 to_email 中的输出。此查询运行良好。但问题是我无法检测到它最终在 to_email 或 from_email 中找到。我希望它最终只给我这封电子邮件所携带的领域。以下是我的电子邮件 ID

SELECT mail_id, from_firstname, from_lastname, from_email, to_firstname, to_lastname, to_email
FROM support_mail sm WHERE
( 

( FIND_IN_SET ('".$email_id."', sm.to_email) ) AND ( (sm.to_firstname <> '') AND (sm.to_firstname <> 'None') )

OR 

( FIND_IN_SET ('".$email_id."', sm.from_email) ) AND ( (sm.from_firstname <> '') AND (sm.from_firstname <> 'None') )

) 
4

1 回答 1

0

尝试在下面使用,它可能会解决您的问题:

SELECT mail_id, from_firstname, from_lastname, from_email, to_firstname, to_lastname, to_email
(IF( FIND_IN_SET ('".$email_id."', sm.to_email) ) AND ( (sm.to_firstname <> '') AND (sm.to_firstname <> 'None') ),"yes","no") AS MailTo,
(IF(FIND_IN_SET ('".$email_id."', sm.from_email) ) AND ( (sm.from_firstname <> '') AND (sm.from_firstname <> 'None')),"yes","no") AS MailFrom
FROM support_mail sm WHERE
( 
OR 

( FIND_IN_SET ('".$email_id."', sm.to_email) ) AND ( (sm.to_firstname <> '') AND (sm.to_firstname <> 'None') )

OR 

( FIND_IN_SET ('".$email_id."', sm.from_email) ) AND ( (sm.from_firstname <> '') AND (sm.from_firstname <> 'None') )
)
于 2012-12-17T09:58:10.017 回答