我正在尝试更改一个查询,该查询不仅允许用户通过输入特定战斗机的姓氏来接收结果,还可以输入战斗机的名字。如何更改下面的查询来完成此操作?
以下是代码:
SELECT distinct
'${searchT}' searchalp,
(SELECT COUNT(fighterId) FROM tblFighter where fighter_lastName like '${searchT}%') totalresults,
A.FighterID,
A.Fighter_FirstName,
A.Fighter_NickName,
if (A.Fighter_Height > 0,
CONCAT(FLOOR(A.Fighter_Height/12), '\' ', MOD(A.Fighter_Height,12), '"'), '') Fighter_Height_inch,
A.Fighter_NormalWeight,
if (A.Fighter_Reach > 0, CONCAT(ROUND(A.Fighter_Reach,0), '"') , '') Fighter_Reach,
A.Fighter_Stance,
CONCAT('/fighter/',REPLACE(REPLACE(LCASE(A.Fighter_FirstName),' ','-'),'.',''),'/',REPLACE(LCASE(A.Fighter_LastName),' ','-'),'/',A.FighterID,'/') fighterURL,
(select count(*) from tblFight_Fighter where FighterID = A.FighterID and OutcomeID = 1) fighterCareerWins, (select count(*) from tblFight_Fighter where FighterID = A.FighterID and OutcomeID = 2) fighterCareerLosses, (select count(*) from tblFight_Fighter where FighterID = A.FighterID and OutcomeID = 3) fighterCareerDraws,
fighter_lastName, FA.AccoladeDescription FROM tblFighter as A LEFT JOIN (SELECT FighterId, AccoladeDescription, AccoladeType
FROM tblAccolade
JOIN tblEvent USING(EventID)
JOIN (SELECT AccoladeID, Max(Event_Date) as MaxAccDate
FROM tblAccolade
JOIN tblEvent ON tblAccolade.EventID = tblEvent.EventID
WHERE AccoladeType = 'Belt' AND AccoladeDescription not like 'WEC%'
GROUP BY AccoladeID) as tmpMaxAccDate ON tblAccolade.AccoladeID = tmpMaxAccDate.AccoladeID
WHERE Event_Date = MaxAccDate) as FA ON FA.FighterId = A.FighterId and FA.AccoladeType = 'Belt' where A.fighter_lastName like '${searchT}%' order by A.fighter_lastName ASC LIMIT ${stInd}, ${lstInd}
答案 0 :(得分:1)
where A.fighter_lastName like '${searchT}%' and A.fighter_firstName like '${searchU}%'
之类的东西应该这样做。如果一个或另一个字符串为空,则搜索将仅基于另一个字符串。