SELECT o.*, g.goods_tax_price_percent, p.*
FROM `ecs_order_goods` AS o
LEFT JOIN `ecs_order_goods` AS p
ON p.product_id = o.product_id
LEFT JOIN `ecs_goods` AS g
ON o.goods_id = g.goods_id
WHERE o.order_id = '93' ORDER BY goods_id
如何获取g.goods_tax_price_percent
的总数不是空值?
我尝试过
SELECT COUNT(g.goods_tax_price_percent IS NOT NULL) AS tax_item
不起作用
---------------------------
TABLE : esc_goods
----------------------------
id | goods_tax_price_percent
----------------------------
1 | NULL
2 | 10
3 | 30
4 | NULL
----------------------------
我要COUNT(g.goods_tax_price_percent IS NOT NULL) AS tax_item
= 2
答案 0 :(得分:0)
您可以使用count()
:
SELECT COUNT(g.goods_tax_price_percent) as tax_item
FROM ecs_order_goods o LEFT JOIN
ecs_order_goods p
ON p.product_id = o.product_id LEFT JOIN
ecs_goods g
ON o.goods_id = g.goods_id
WHERE o.order_id = 93 ;
该查询的LEFT JOIN
可能是INNER JOIN
。