我正在尝试生成一个用于智能搜索字段的查询,ala google 建议。
我无法直接形成查询,尽管我可以通过日志查看进行了哪些查询。
我已经发布了发送的查询,它有语法错误,但我不确定为什么。
SELECT DISTINCT IF(guests.passport != '', Concat(guests.passport,
IF(
guests.lastname !=
''
OR guests.passport!= '',
Concat
(' (',
IF(guests.lastname !=
'',
guests.lastname,
'{blank}')
, ', ',
IF(
guests.firstname != ''
, guests.passport,
'{blank}')
, ')'), '')),
IF(guests.lastname != ''
OR guests.passport!= '', Concat(IF(guests.lastname != '',
guests.lastname,
'{blank}'), ', ',
IF(
guests.passport!= '',
guests.passport, '{blank}')),
''
)) AS display,
`guests`.`uuid` AS VALUE,
as secondary,
guests.id AS classname
FROM guests
WHERE ( guests.id = 0 )
AND ( ( guests.firstname LIKE 'b%'
OR guests.lastname LIKE 'b%'
OR guests.passport LIKE 'b%' )
OR (( guests.firstname LIKE 'b%'
OR guests.firstname LIKE '% b%'
OR guests.lastname LIKE 'b%'
OR guests.lastname LIKE '% b%'
OR guests.passport LIKE 'b%'
OR guests.passport LIKE '% b%' )) )
ORDER BY IF(guests.passport != '', Concat(guests.passport,
IF(guests.lastname != ''
OR
guests.passport!= '',
Concat
(' (',
IF(guests.lastname != '',
guests.lastname, '{blank}')
, ', ',
IF(
guests.firstname != ''
, guests.passport,
'{blank}')
, ')'), '')),
IF(guests.lastname != ''
OR guests.passport!= '', Concat(IF(guests.lastname != '',
guests.lastname,
'{blank}'
), ', ',
IF(
guests.passport!= '', guests.passport,
'{blank}'
)),
''
))
LIMIT 0, 8
该查询是否有任何明显的错误?