简体   繁体   English

将单行查询与多行查询相乘

[英]Multiply single-row query with multi-row query


Hi! 嗨! i have a query like this: SELECT (subquery1) * (subquery2); 我有这样的查询:SELECT(subquery1)*(subquery2); The problem is that subquery1 returns 1 row and subquery2 returns more than one row, and i got error 1242: Subquery returns more than one row. 问题是subquery1返回1行,而subquery2返回多于一行,并且我收到错误1242:Subquery返回多于一行。 What i want is: say subquery2 returns 15 rows for example, i want the following output: 我想要的是:比如说subquery2返回15行,我想要以下输出:

subquery2(1) * subquery1
subquery2(2) * subquery1
subquery2(3) * subquery1
subquery2(4) * subquery1
......
......
subquery2(15) * subquery1

How can i achieve this? 我怎样才能做到这一点? thanks 谢谢

You need to JOIN between whatever tables are in subquery1 and 2. This will give you the "for each row" functionality you're looking for. 您需要在子查询1和2中的任何表之间进行JOIN。这将为您提供所需的“为每一行”功能。 If you give more information, more help will come. 如果您提供更多信息,将会有更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM