我有一个触发器,当我写入另一个表时,我试图写入一个表。
问题是,我正在读取的表是在这样的几行上存储1个条目(不是我的表,插件写这个):
406 test5 74 63 2014-11-04 13:43:35
407 test5 75 63 2014-11-04 13:43:35
408 test5@w.com 76 63 2014-11-04 13:43:35
409 12345678909 78 63 2014-11-04 13:43:35
410 Movable Assets 79 63 2014-11-04 13:43:35
我正在使用以下内容写入我的新表:
INSERT INTO `new_memberlist`
(FirstName, LastName, Email, Phone, InterestedIn, Province, Status, DateRegistered)
(
select
MAX(case when field_id = 74 and entry_id = (SELECT MAX(entry_id) FROM ch_arf_entry_values) then entry_value end) as FirstName,
MAX(case when field_id = 75 and entry_id = (SELECT MAX(entry_id) FROM ch_arf_entry_values) then entry_value end) as LastName,
MAX(case when field_id = 76 and entry_id = (SELECT MAX(entry_id) FROM ch_arf_entry_values) then entry_value end) as Email,
MAX(case when field_id = 78 and entry_id = (SELECT MAX(entry_id) FROM ch_arf_entry_values) then entry_value end) as Phone,
MAX(case when field_id = 79 and entry_id = (SELECT MAX(entry_id) FROM ch_arf_entry_values) then (
select distinct concat(
SUBSTRING_INDEX(SUBSTRING_INDEX( SUBSTRING_INDEX(entry_value,'"',2),'"',2),'"',-1),
',',
SUBSTRING_INDEX(SUBSTRING_INDEX( SUBSTRING_INDEX(entry_value,'"',4),'"',4),'"',-1)
)
)
end) as InterestedIn,
MAX(case when field_id = 81 and entry_id = (SELECT MAX(entry_id) FROM ch_arf_entry_values) then (
select distinct concat(
SUBSTRING_INDEX(SUBSTRING_INDEX( SUBSTRING_INDEX(entry_value,'"',2),'"',2),'"',-1),
',',
SUBSTRING_INDEX(SUBSTRING_INDEX( SUBSTRING_INDEX(entry_value,'"',4),'"',4),'"',-1),
',',
SUBSTRING_INDEX(SUBSTRING_INDEX( SUBSTRING_INDEX(entry_value,'"',6),'"',6),'"',-1),
',',
SUBSTRING_INDEX(SUBSTRING_INDEX( SUBSTRING_INDEX(entry_value,'"',8),'"',8),'"',-1),
',',
SUBSTRING_INDEX(SUBSTRING_INDEX( SUBSTRING_INDEX(entry_value,'"',10),'"',10),'"',-1),
',',
SUBSTRING_INDEX(SUBSTRING_INDEX( SUBSTRING_INDEX(entry_value,'"',12),'"',12),'"',-1),
',',
SUBSTRING_INDEX(SUBSTRING_INDEX( SUBSTRING_INDEX(entry_value,'"',14),'"',14),'"',-1),
',',
SUBSTRING_INDEX(SUBSTRING_INDEX( SUBSTRING_INDEX(entry_value,'"',16),'"',16),'"',-1),
',',
SUBSTRING_INDEX(SUBSTRING_INDEX( SUBSTRING_INDEX(entry_value,'"',18),'"',18),'"',-1)
)
)
end) as Province,
'1' as Status,
NOW() as DateRegistered
from ch_arf_entry_values
WHERE entry_id = (SELECT MAX(entry_id) FROM ch_arf_entry_values)
GROUP BY entry_id
LIMIT 1
)
不幸的是,它被写了几次,只有顶部条目是正确的1,我想保留哪个具有所有值而且没有NULLS:
892 test5 test5 test5@w.com 12345678909 Movable Assets,Movable Assets NULL 1 2014-11-04 15:43:35
891 test5 test5 test5@w.com 12345678909 NULL NULL 1 2014-11-04 15:43:35
890 test5 test5 test5@w.com NULL NULL NULL 1 2014-11-04 15:43:35
889 test5 test5 NULL NULL NULL NULL 1 2014-11-04 15:43:35
888 test5 NULL NULL NULL NULL NULL 1 2014-11-04 15:43:35
887 NULL NULL NULL NULL NULL NULL 1 2014-11-04 15:43:35
非常感谢任何协助。
答案 0 :(得分:2)
您发布的问题可能没问题,但您不确定您到底需要什么。如果我理解你的要求,那么这就是下面给出的答案。只需包含限制空值的where条件。
WHERE entry_id = (SELECT MAX(entry_id) FROM ch_arf_entry_values) AND firstname!=NULL and lastname!=NULL
在此,您可以包含不应为空值的列(例如电子邮件,电话和其他)。如果不起作用,请不要犹豫,提出或发布问题。我们随时为您提供帮助。