gpt4 book ai didi

mysql - 搜索 SQL 数据库和 CONCAT 数据

转载 作者:行者123 更新时间:2023-11-29 18:45:20 25 4
gpt4 key购买 nike

对 php 和 sql 不熟悉,所以我会尝试解释:

我在 PHP 中有一个搜索字段,我正在尝试按与用户输入的内容相匹配的“ProposalName”进行搜索。

打印效果很好:

SELECT
rec_proposal.ProposalID,
ProposalName,
Status,
researcher.FirstName,
researcher.LastName,
reviewer.FirstName as revFirstName,
reviewer.LastName as revLastName,
reviewer.UserID as revUserID,
review.ReviewDate as revDate,
rec_proposal.DateSubmitted
FROM rec_proposal
INNER JOIN User AS researcher
ON rec_proposal.userid = researcher.UserID
LEFT JOIN review
ON rec_proposal.ProposalID=review.ProposalID
LEFT JOIN User as reviewer
ON review.UserID=reviewer.UserID

但现在使用所有列,我需要上面的代码来执行类似的操作

  SELECT * FROM rec_proposal WHERE CONCAT (ProposalName) LIKE'%test%'

因此,如果用户输入单词“test”,您将看到包含单词 test 的 ProposalName

最佳答案

只需添加您的 WHERE 子句,它就应该可以工作。正如 scaisEdge 在他们的评论中指出的那样,如果您只是评估单个列,则不需要 CONCAT() :

SELECT
rec_proposal.ProposalID,
ProposalName,
Status,
researcher.FirstName,
researcher.LastName,
reviewer.FirstName as revFirstName,
reviewer.LastName as revLastName,
reviewer.UserID as revUserID,
review.ReviewDate as revDate,
rec_proposal.DateSubmitted
FROM rec_proposal
INNER JOIN User AS researcher
ON rec_proposal.userid = researcher.UserID
LEFT JOIN review
ON rec_proposal.ProposalID=review.ProposalID
LEFT JOIN User as reviewer
ON review.UserID=reviewer.UserID
WHERE rec_proposal.ProposalName LIKE '%test%'

关于mysql - 搜索 SQL 数据库和 CONCAT 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44702813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com