如何找到导致从两个不同的日期比较如何从两个不同的日期比较中找到结果集?
如何找到period1_label_cost设置,period2_label_cost在此查询,而无需使用此查询?
只有period1_label_cost列的值越来越
select distinct customers.id as customer_id, customers.first_name as first_name, customers.last_name as last_name, SUM(orders.total_cost) as period1_label_cost
from customers inner join orders
on customers.id= orders.customer_id
where
date(orders.created_at) between 'start_date1' and 'end_date1'
group by customers.id , customers.first_name, customers.last_name, customers.preferred
having(SUM(orders.total_cost) > sales_exceeded
intersect
select distinct customers.id as customer_id, customers.first_name as first_name, customers.last_name as last_name,
customers.preferred as preferred, SUM(orders.total_cost) as period2_label_cost
from customers inner join orders
on customers.id= orders.customer_id
where
date(orders.created_at) between start_date2 and end_date2
group by customers.id , customers.first_name, customers.last_name, customers.preferred
having(SUM(orders.total_cost) < sales_below) order by first_name asc
在mysql中相交? –