我对此很新,所以我对MySQL有疑问。我在openCart中查询:
$sql = "SELECT cp.category_id AS category_id,
GROUP_CONCAT(cd1.name
ORDER BY cp.level SEPARATOR ' > ') AS name,
c1.parent_id,
c1.sort_order
FROM " . DB_PREFIX . "category_path cp
LEFT JOIN " . DB_PREFIX . "category c1 ON (cp.category_id = c1.category_id)
LEFT JOIN " . DB_PREFIX . "category c2 ON (cp.path_id = c2.category_id)
LEFT JOIN " . DB_PREFIX . "category_description cd1 ON (cp.path_id = cd1.category_id)
LEFT JOIN " . DB_PREFIX . "category_description cd2 ON (cp.category_id = cd2.category_id)
WHERE cd1.language_id = '" . (int)$this->config->get('config_language_id') . "'
AND cd2.language_id = '" . (int)$this->config->get('config_language_id') ."'";
在MySQL中,我添加了新的列“show_menu”(它可以是NULL或1),现在我想更改我的查询,它将只返回show_menu = 1的类别
据我所知,我需要这样的东西:WHERE show_menu IS 1。 也许任何人都可以帮助把它放在哪里?因为我试过,但没有运气......
答案 0 :(得分:2)
使用show_menu = 1
或show_menu IS NOT NULL
您无法使用' ='具有空值的运算符。
答案 1 :(得分:1)
只需将以下内容添加到WHERE子句中:
... AND show_menu = 1
就像
SELECT * FROM tablename
WHERE conditions_from_your_existing_query
AND show_menu = 1
答案 2 :(得分:0)
您可以使用show_menu = 1
,也可以使用show_menu is not null
。无论哪种方式都可行。