我有两个独立显示的查询。
SELECT 'New Orders' AS 'Type', @new_customers AS 'Total', CONCAT(ROUND((@new_customers / @total_purchases) * 100, 1), '%') AS 'Percentage';
SELECT 'Repeat Orders' AS 'Type', @repeat_customers AS 'Total', CONCAT(ROUND((@repeat_customers / @total_purchases) * 100, 1), '%') AS 'Percentage';
我想将它们一起列出,这样的演出
+---------------+-------+------------+
| Type | Total | Percentage |
+---------------+-------+------------+
| New Orders | 4 | 11.4% |
| Repeat Orders | 4 | 11.4% |
+---------------+-------+------------+
这是变量和视图
## SQL Variables
SELECT COUNT(DISTINCT customer_email) FROM sales_flat_order INTO @new_customers;
SELECT COUNT(customer_email) FROM view_orders WHERE total_orders > 1 INTO @repeat_customers;
## VIEW Customer total orders
CREATE VIEW foodhub_magento.v_orders AS
SELECT
customer_email, COUNT(*) AS total_orders
FROM
foodhubsales_flat_order
GROUP BY
customer_email
HAVING
COUNT(customer_email) > 1;
您可以只使用union all
运算符:
SELECT 'New Orders' AS 'Type', @new_customers AS 'Total', CONCAT(ROUND((@new_customers / @total_purchases) * 100, 1), '%') AS 'Percentage'
UNION ALL
SELECT 'Repeat Orders' AS 'Type', @repeat_customers AS 'Total', CONCAT(ROUND((@repeat_customers / @total_purchases) * 100, 1), '%') AS 'Percentage';
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句