Monday, 15 April 2013

mysql - Joining two queries to display in the same -



mysql - Joining two queries to display in the same -

i have 2 queries display independently.

select 'new orders' 'type', @new_customers 'total', concat(round((@new_customers / @total_purchases) * 100, 1), '%') 'percentage'; select 'repeat orders' 'type', @repeat_customers 'total', concat(round((@repeat_customers / @total_purchases) * 100, 1), '%') 'percentage';

i list them show such

+---------------+-------+------------+ | type | total | percentage | +---------------+-------+------------+ | new orders | 4 | 11.4% | | repeat orders | 4 | 11.4% | +---------------+-------+------------+

here variables , view

## sql variables select count(distinct customer_email) sales_flat_order @new_customers; select count(customer_email) view_orders total_orders > 1 @repeat_customers; ## view client total orders create view foodhub_magento.v_orders select customer_email, count(*) total_orders foodhubsales_flat_order grouping customer_email having count(customer_email) > 1;

you utilize union all operator:

select 'new orders' 'type', @new_customers 'total', concat(round((@new_customers / @total_purchases) * 100, 1), '%') 'percentage' union select 'repeat orders' 'type', @repeat_customers 'total', concat(round((@repeat_customers / @total_purchases) * 100, 1), '%') 'percentage';

mysql sql

No comments:

Post a Comment