• <small id='fl43W'></small><noframes id='fl43W'>

    • <bdo id='fl43W'></bdo><ul id='fl43W'></ul>

        <legend id='fl43W'><style id='fl43W'><dir id='fl43W'><q id='fl43W'></q></dir></style></legend>
      1. <tfoot id='fl43W'></tfoot>
        <i id='fl43W'><tr id='fl43W'><dt id='fl43W'><q id='fl43W'><span id='fl43W'><b id='fl43W'><form id='fl43W'><ins id='fl43W'></ins><ul id='fl43W'></ul><sub id='fl43W'></sub></form><legend id='fl43W'></legend><bdo id='fl43W'><pre id='fl43W'><center id='fl43W'></center></pre></bdo></b><th id='fl43W'></th></span></q></dt></tr></i><div id='fl43W'><tfoot id='fl43W'></tfoot><dl id='fl43W'><fieldset id='fl43W'></fieldset></dl></div>

        加入两个选择语句

        joining two select statements(加入两个选择语句)

              <legend id='rcARN'><style id='rcARN'><dir id='rcARN'><q id='rcARN'></q></dir></style></legend>

                  <tbody id='rcARN'></tbody>
                <i id='rcARN'><tr id='rcARN'><dt id='rcARN'><q id='rcARN'><span id='rcARN'><b id='rcARN'><form id='rcARN'><ins id='rcARN'></ins><ul id='rcARN'></ul><sub id='rcARN'></sub></form><legend id='rcARN'></legend><bdo id='rcARN'><pre id='rcARN'><center id='rcARN'></center></pre></bdo></b><th id='rcARN'></th></span></q></dt></tr></i><div id='rcARN'><tfoot id='rcARN'></tfoot><dl id='rcARN'><fieldset id='rcARN'></fieldset></dl></div>

                <tfoot id='rcARN'></tfoot>
                • <bdo id='rcARN'></bdo><ul id='rcARN'></ul>
                • <small id='rcARN'></small><noframes id='rcARN'>

                  本文介绍了加入两个选择语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  谁能告诉我为什么以下不起作用?它抱怨两个选择之间的连接关键字附近出现语法错误.

                  Can anyone tell me why the following won't work? It complains of a syntax error near the join key word between the two selects.

                  SELECT * 
                  FROM ( select * from orders_products inner JOIN orders ON orders_products.orders_id = orders.orders_id  where products_id = 181) 
                  as A
                  
                  join 
                  
                  SELECT * 
                  FROM ( select * from orders_products INNER JOIN orders ON orders_products.orders_id = orders.orders_id  where products_id = 180) 
                  as B
                  
                  on A.orders_id=B.orders_id
                  

                  基本上我的第一个 SELECT 从一个表中提取某个产品的所有订单信息,并从另一个表中提取订购的数量并将它们连接在一起.第二个 SELECT 对另一个产品做同样的事情.

                  Basically my first SELECT pulls all the order info for a certain product from one table and pulls the quantity ordered from another and joins them together. The second SELECT does the same thing for another product.

                  现在,我有

                  _______A_________         _______B_________
                  O_ID P_ID Q O_ID P_ID Q
                  1 180 3 1 181 11
                  2 180 9 2 181 6
                  3 180 5 3 181 3

                  而且,我想使用另一个连接

                  And, using another join I want to get


                  Q_ID P_ID1 Q1 P_ID2 Q2
                  1 180 3 181 11
                  2 180 9 181 6
                  3 180 5 181 3

                  也许我在这里采取了错误的方法.有什么建议吗?

                  Maybe I am taking a wrong approach here. Any suggestions?

                  更新:以下是 RedFilter 指示后对我有用的方法:

                  UPDATE: Here is what worked for me after pointers by RedFilter:

                  (SELECT * 
                  FROM (
                  SELECT * FROM orders_products
                  INNER JOIN orders ON orders_products.orders_id = orders.orders_id
                  WHERE products_id =181) AS A
                  LEFT JOIN (
                  SELECT * FROM orders_products
                  INNER JOIN orders ON orders_products.orders_id = orders.orders_id
                  WHERE products_id =180) AS B ON A.orders_id = B.orders_id
                  )
                  UNION (
                  SELECT * 
                  FROM (
                  SELECT * 
                  FROM orders_products
                  INNER JOIN orders ON orders_products.orders_id = orders.orders_id
                  WHERE products_id =181
                  ) AS C
                  RIGHT JOIN (
                  SELECT * 
                  FROM orders_products
                  INNER JOIN orders ON orders_products.orders_id = orders.orders_id
                  WHERE products_id =180
                  ) AS D ON C.orders_id = D.orders_id
                  ) 
                  

                  推荐答案

                  不确定您要做什么,但您有两个选择子句.改为这样做:

                  Not sure what you are trying to do, but you have two select clauses. Do this instead:

                  SELECT * 
                  FROM ( SELECT * 
                         FROM orders_products 
                         INNER JOIN orders ON orders_products.orders_id = orders.orders_id 
                         WHERE products_id = 181) AS A
                  JOIN ( SELECT * 
                         FROM orders_products 
                         INNER JOIN orders ON orders_products.orders_id = orders.orders_id
                         WHERE products_id = 180) AS B
                  
                  ON A.orders_id=B.orders_id
                  

                  更新:

                  您可能可以将其简化为这样的:

                  You could probably reduce it to something like this:

                  SELECT o.orders_id, 
                         op1.products_id, 
                         op1.quantity, 
                         op2.products_id, 
                         op2.quantity
                  FROM orders o
                  INNER JOIN orders_products op1 on o.orders_id = op1.orders_id  
                  INNER JOIN orders_products op2 on o.orders_id = op2.orders_id  
                  WHERE op1.products_id = 180
                  AND op2.products_id = 181
                  

                  这篇关于加入两个选择语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)

                  • <tfoot id='2cYxq'></tfoot>

                    <i id='2cYxq'><tr id='2cYxq'><dt id='2cYxq'><q id='2cYxq'><span id='2cYxq'><b id='2cYxq'><form id='2cYxq'><ins id='2cYxq'></ins><ul id='2cYxq'></ul><sub id='2cYxq'></sub></form><legend id='2cYxq'></legend><bdo id='2cYxq'><pre id='2cYxq'><center id='2cYxq'></center></pre></bdo></b><th id='2cYxq'></th></span></q></dt></tr></i><div id='2cYxq'><tfoot id='2cYxq'></tfoot><dl id='2cYxq'><fieldset id='2cYxq'></fieldset></dl></div>
                      <legend id='2cYxq'><style id='2cYxq'><dir id='2cYxq'><q id='2cYxq'></q></dir></style></legend>
                      • <bdo id='2cYxq'></bdo><ul id='2cYxq'></ul>
                            <tbody id='2cYxq'></tbody>
                          • <small id='2cYxq'></small><noframes id='2cYxq'>