Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining Queries

Status
Not open for further replies.

michaela18

Technical User
Sep 9, 2009
37
US
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
 
you cannot combine those queries, because bofadem contain a syntax error -- there is no "agg" table in the FROM clause

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top