这是我在第一个查询上的2个sql查询我希望将它用作表格,在第二个查询中我想加入第一个查询,我假设一个表
e.g。
首先查询:
SELECT sale.salesManID, sale.companyName, sale.sellingPrice
from sale Inner Join carModel
On (sale.companyName = carModel.companyName) AND (carModel.size>10) ;
第二次查询:
SELECT salesMan.salesmanID, salesMan.name, SUM(firstQuery.sellingPrice)
FROM salesMan
INNER JOIN firstQuery
ON salesMan.salesmanID = firstQuery.salesManID
GROUP BY salesmanID, name;
我该怎么办?提前谢谢。
答案 0 :(得分:1)
如果我正确理解了这个问题(虽然我不确定你为什么要这样做......):
IF object_id('tempdb ..#firstQuery)IS NOT NULL DROP TABLE #firstQuery;
SELECT sale.salesManID,sale.companyName,sale.sellingPrice INTO #firstQuery 来自销售内部加入carModel On(sale.companyName = carModel.companyName)AND(carModel.size> 10);
SELECT salesMan.salesmanID,salesMan.name, SUM(firstQuery.sellingPrice)FROM salesMan INNER JOIN #firstQuery ON salesMan.salesmanID = firstQuery.salesManID GROUP BY salesmanID, 名;
答案 1 :(得分:0)
这不是一个明确的问题。你的意思是在连接上使用子查询???
也许你可以看看这个帖子:
mysql subquery inside a LEFT JOIN
MySQL correlated subquery in JOIN syntax
或只是谷歌mysql join subquery
你也可以看一下这篇文章:How can my application benefit from temporary tables?e