michaela18
Technical User
How can I combine these 2 queries? They're basically the same, just one takes the past 7 days and the other takes the past 1 day. Is there a way to do the first 7 days? There is a field in VZ table that has Start_Date. How can I write that? Like VZ.start_date + 7?
SELECT VZ.name,Sales.io_id, line.id, line.description,
SUM( sales.volume) AS Volumn,
SUM(sales.Sales)AS Sales,
CONCAT((SUM(Sales.sales)/SUM(sales.volumn))*100,'%') AS ATC,
CONCAT(vz.goal,'%') AS Goal
FROM sales_daily sales,line_items line, line_Info VZ
WHERE sales.io_id = line.io_id AND sales.io_id = VZ.id AND sales.io_line_item_id = line.id
AND sales.io_id IN('25761','25761','26889','24817','27991','25016','26338','25740','27707','26442','27644','27921','25960','25961','27305','26728','26351','26257','26564','26443','27738')
AND agg.date >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)
GROUP BY sales.io_id, sales.io_line_item_id
SELECT VZ.name,Sales.io_id, line.id, line.description,
SUM( sales.volume) AS Volumn,
SUM(sales.Sales)AS Sales,
CONCAT((SUM(Sales.sales)/SUM(sales.volumn))*100,'%') AS ATC,
CONCAT(vz.goal,'%') AS Goal
FROM sales_daily sales,line_items line, line_Info VZ
WHERE sales.io_id = line.io_id AND sales.io_id = VZ.id AND sales.io_line_item_id = line.id
AND sales.io_id IN('25761','25761','26889','24817','27991','25016','26338','25740','27707','26442','27644','27921','25960','25961','27305','26728','26351','26257','26564','26443','27738')
AND agg.date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 DAY)
GROUP BY sales.io_id, sales.io_line_item_id
SELECT VZ.name,Sales.io_id, line.id, line.description,
SUM( sales.volume) AS Volumn,
SUM(sales.Sales)AS Sales,
CONCAT((SUM(Sales.sales)/SUM(sales.volumn))*100,'%') AS ATC,
CONCAT(vz.goal,'%') AS Goal
FROM sales_daily sales,line_items line, line_Info VZ
WHERE sales.io_id = line.io_id AND sales.io_id = VZ.id AND sales.io_line_item_id = line.id
AND sales.io_id IN('25761','25761','26889','24817','27991','25016','26338','25740','27707','26442','27644','27921','25960','25961','27305','26728','26351','26257','26564','26443','27738')
AND agg.date >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)
GROUP BY sales.io_id, sales.io_line_item_id
SELECT VZ.name,Sales.io_id, line.id, line.description,
SUM( sales.volume) AS Volumn,
SUM(sales.Sales)AS Sales,
CONCAT((SUM(Sales.sales)/SUM(sales.volumn))*100,'%') AS ATC,
CONCAT(vz.goal,'%') AS Goal
FROM sales_daily sales,line_items line, line_Info VZ
WHERE sales.io_id = line.io_id AND sales.io_id = VZ.id AND sales.io_line_item_id = line.id
AND sales.io_id IN('25761','25761','26889','24817','27991','25016','26338','25740','27707','26442','27644','27921','25960','25961','27305','26728','26351','26257','26564','26443','27738')
AND agg.date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 DAY)
GROUP BY sales.io_id, sales.io_line_item_id