【发布时间】:2021-04-24 12:55:35
【问题描述】:
我的SQL逻辑有问题,我必须检查数据库中的数组类别的值是否与数值匹配以检索所有匹配的元素,需要帮助
在我的表格产品中,我保存了像 varchar 这样的类别列:
这是我的请求函数:
function getCategoryTrendingProduct($categoryId, $skip, $limit)
{
$sql = "SELECT id as product_id, name as product_name, price as product_price, image as product_image, rating as product_rating, review as product_review FROM products WHERE JSON_EXTRACT(category, '$.?') = ? ORDER BY product_sale DESC LIMIT ?, ?";
$query = $this->db->query($sql, array($categoryId, $skip, $limit));
$rs = $query->result_array();
return $rs;
}
我想提取类别列并验证它是否包含 categoryId.. 帮忙!
【问题讨论】:
-
(1) 用您正在使用的数据库标记您的问题。 (2) 表格格式的样本数据会有所帮助。
-
如果
categoryId为 11,则返回第 4 行,如果为 6,则返回第 1 行,如果$categoryId为 1,则返回除第一行之外的所有行,对吗? -
不,因为我有一个产品表,我想检索所有指定类别的产品,如果我一开始没有解释清楚,对不起
-
SQL Server 抱歉
标签: sql sql-server database