0

我的数据:

桌子 我如何到那里?我试图在我的 TAX 表上创建一个 MySQL 视图。

创建视图 TaxSplitPerOrder AS SELECT OrderNumber, tax_invoiced, total_invoiced, created_at, tax_percent, SUM( tax_invoiced_order_item) FROM test GROUP by OrderNumber;

谁能帮我?

4

2 回答 2

1

SELECT您需要在GROUP BY子句中包含您的所有其他非汇总列。您可能也想求和total_invoiced,否则每个订单号仍然有 2 行。

于 2016-05-05T00:19:07.067 回答
0

查询:

SELECT OrderNumber, tax_invoiced, total_invoiced, created_at, MAX(CASE WHEN tax_percent= 21 THEN tax_invoiced_order_itemEND) tax_21, MAX(CASE WHEN tax_percent= 6 THEN tax_invoiced_order_itemEND)tax_6 从测试组按订单号;

于 2016-05-05T00:39:45.710 回答