gpt4 book ai didi

php - Mysql中使用where和Like子句过滤数据

转载 作者:行者123 更新时间:2023-11-29 08:05:46 30 4
gpt4 key购买 nike

我正在 mysql 数据库中使用 LIKE 关键字过滤数据。这是以下查询:

Select c.c_id, c.c_name, slab, 
COUNT(c.c_id) as tot_visit,
SUM(t.bill) as tot_revenue, c.priority, c.ratings
From tbl_customer c
inner join tbl_transaction t on c.c_id=t.c_id
group by c.c_id
Where r_id="r1" AND c.slab LIKE "%teen%"

当我删除这个 -> AND c.ocation LIKE "%teen%" <- 子句时,查询工作正常..否则它会给出空行集。

我正在努力,但没有克服它。任何帮助将不胜感激。

编辑我正在按青少年、青年和老年人的年龄层过滤数据。相同的代码在其他 php 文件中运行良好,但在本文件中则不然。

if(isset($_GET['submit']))
{
if (isset($_GET["teen"]))
{
$arguments[] = "c.slab LIKE '%teen%'";
}
if (isset($_GET["young"])) {
$arguments[] = "c.slab LIKE '%young%'";
}
if (isset($_GET["senior"]))
{
$arguments[] = "c.slab LIKE '%senior%'";
}

if(!empty($arguments)) {
$str = implode(' or ',$arguments);
$qry = mysql_query('Select c.c_id, c.c_name, c.slab,
COUNT(c.c_id) as tot_visit,
SUM(t.bill) as tot_revenue, c.priority, c.ratings
From tbl_customer c
inner join tbl_transaction t on c.c_id=t.c_id
Where r_id="r1" AND "'.$str.'"
group by c.c_id');

不明白这一切有什么问题。请帮忙。

最佳答案

尝试在groupby之前写where条件

Select c.c_id, c.c_name, slab, 
COUNT(c.c_id) as tot_visit,
SUM(t.bill) as tot_revenue, c.priority, c.ratings
From tbl_customer c
inner join tbl_transaction t on c.c_id=t.c_id
Where r_id="r1" AND c.occupation LIKE "%teen%"
group by c.c_id

关于php - Mysql中使用where和Like子句过滤数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22759842/

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