gpt4 book ai didi

php - 如何读取sql中的当前值

转载 作者:行者123 更新时间:2023-11-29 08:55:57 25 4
gpt4 key购买 nike

我创建了一个搜索功能:

SELECT
tbl_place.id AS id,
tbl_place.metalink AS metalink,
tbl_place.title AS title,
tbl_place.img_thumbnail AS img_thumbnail,
tbl_place.category1_id AS category1_id,
tbl_place.category2_id AS category2_id,
tbl_place.category3_id AS category3_id,
tbl_place.region_id AS region_id,
tbl_place.subregion_id AS subregion_id,
tbl_place.summary AS summary,
(SELECT COUNT(tbl_place.title) FROM tbl_place) AS total_show_up
FROM tbl_place
WHERE
tbl_place.title LIKE '%$keywords[0]%' AND
tbl_place.title LIKE '%$keywords[1]%'

如果我搜索关键字:“Pizza Store”,它将显示如下内容:

* Pizza Store
* Pizza Store Manhattan
* Pizza Store California
* Pizza Store California
* Pizza Store Texas
* Pizza Store California

我想做的是,在查询仍在使用关键字搜索时,还计算每个 tbl_place.title 显示的次数。我希望结果变成这样:

* Pizza Store - showed 1 time
* Pizza Store Manhattan - showed 1 time
* Pizza Store California - showed 3 times
* Pizza Store California - showed 3 times
* Pizza Store Texas - showed 1 time
* Pizza Store California - showed 3 times

是否有任何语法可以在 SELECT 时读取 tbl_place 的当前值?

我相信我改变了查询的这一部分:

(SELECT COUNT(tbl_place.title) FROM tbl_place) AS total_show_up

最佳答案

尝试这样的方法:

SELECT
p1.title, pj.total
FROM
pizza p1
JOIN
(
SELECT
p2.title title, COUNT(p2.id) total
FROM pizza p2
WHERE p2.title LIKE '%Pizza%' AND p2.title LIKE '%Store%'
GROUP BY p2.title
) AS pj
ON p1.title=pj.title

关于php - 如何读取sql中的当前值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9989046/

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