我的数据:
我如何到那里?我试图在我的 TAX 表上创建一个 MySQL 视图。
创建视图 TaxSplitPerOrder AS SELECT
OrderNumber
, tax_invoiced
, total_invoiced
, created_at
, tax_percent
, SUM( tax_invoiced_order_item
) FROM test GROUP by OrderNumber;
谁能帮我?
SELECT
您需要在GROUP BY
子句中包含您的所有其他非汇总列。您可能也想求和total_invoiced
,否则每个订单号仍然有 2 行。
查询:
SELECT OrderNumber
, tax_invoiced
, total_invoiced
, created_at
, MAX(CASE WHEN tax_percent
= 21 THEN tax_invoiced_order_item
END) tax_21
, MAX(CASE WHEN tax_percent
= 6 THEN tax_invoiced_order_item
END)tax_6
从测试组按订单号;