首先检查一下这段代码。它看起来应该可以工作,但实际上却不能!(惊喜!)
无论如何,这是我最先尝试的:
SELECT
Status as status,
Address as ip,
PCName as pc_name,
(Numbers.Phone = 'CPU/' + PCName) as cpu_contact,
(Numbers.Phone = 'PC/' + PCName) as pc_contact,
(Numbers.Phone = 'LOGIN/' + PCName) as login_contact,
FROM IPAddress
WHERE $where --Generated In code
JOIN Numbers
ON ('CPU/' + PCName = Numbers.Phone)
OR ('PC/' + PCName = Numbers.Phone)
OR ('LOGIN/' + PCName = Numbers.Phone)
我需要一些布尔计算字段,并根据相似条件进行连接。我还希望结果能够折叠成单行。例如,我认为当前设置会执行以下操作:
status ip cpu_contact pc_contact login_contact
-----------------------------------------------
foo bar true false false
foo bar false true false
foo bar false false true
当然,我更愿意。
status ip cpu_contact pc_contact login_contact
-----------------------------------------------
foo bar true true true
有什么想法吗?重新设计数据库不是一个选项。如果是的话,我会这样做 :-)