目标
仅在参数不为空时使用“where”子句。
问题
我不知道语法。
我的内容
以下语法无效。
CREATE DEFINER=`root`@`localhost` PROCEDURE `getProductsListForHome`
(IN `inOffer` INT, IN `categoryId` INT)
BEGIN
SELECT (MIN(`map`.`Product_Price`)) as `minProductPrice`,
(MAX(`map`.`Product_Price`)) as `maxProductPrice`,
`pr`.`Product_Name` as `productName`,
`ca`.`Category_Name` as `categoryName`
FROM `bm_market_products` as `map`
JOIN `bm_products` as `pr` ON `map`.`Product_Id` = `pr`.`Product_Id`
JOIN `bm_products_category_relationship` as `car`
ON `pr`.`Product_Id` = `car`.`Product_Id`
JOIN `bm_product_categories` as `ca` ON `car`.`Category_Id` =
`ca`.`Category_Id`
WHERE `map`.`Product_State` = inOffer
IF (`categoryId` != null) THEN
AND `ca`.`Category_Id` = `categoryId`
END IF;
GROUP BY `map`.`Product_Id`;
END
问题出在第19行。
重复的问题?
我不这样认为。我搜索了这个主题,但没有成功——所以我来这里发帖。
细节
我在这里阅读了关于控制流函数的内容,但对我来说仍然很困惑。
提前感谢!