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

    1. <legend id='i0lku'><style id='i0lku'><dir id='i0lku'><q id='i0lku'></q></dir></style></legend>

      <small id='i0lku'></small><noframes id='i0lku'>

        <bdo id='i0lku'></bdo><ul id='i0lku'></ul>

        <tfoot id='i0lku'></tfoot>

      1. IN 子句中的 SQL 多列

        时间:2023-09-19

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

                <tfoot id='0LZcO'></tfoot>

                  <tbody id='0LZcO'></tbody>
              • <small id='0LZcO'></small><noframes id='0LZcO'>

                  <bdo id='0LZcO'></bdo><ul id='0LZcO'></ul>
                • 本文介绍了IN 子句中的 SQL 多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我们需要根据给定列的某些值集查询表,我们可以简单地使用 IN 子句.

                  但是如果需要基于多列执行查询,我们不能使用IN子句(在SO线程中grepped.)

                  从其他 SO 线程,我们可以使用连接或存在子句等来规避此问题.但是如果主表和搜索数据都在数据库中,它们都可以工作.

                  例如用户表:名字,姓氏,城市

                  给定一个 (firstname, lastName) 元组列表,我需要获取城市.

                  我可以想到以下解决方案.

                  1

                  构造一个选择查询,如,

                  SELECT city from user where (firstName=x and lastName=y) or (firstName=a and lastName=b) or .....

                  2

                  将所有 firstName、lastName 值上传到临时表中,并在用户"表和新临时表之间执行连接.

                  是否有解决此问题的任何选项?一般而言,解决此问题的首选方法是什么?

                  解决方案

                  你可以这样做:

                  SELECT city FROM user WHERE (firstName, lastName) IN (('a', 'b'), ('c', 'd'));

                  sqlfiddle.>

                  If we need to query a table based on some set of values for a given column, we can simply use the IN clause.

                  But if query need to be performed based on multiple columns, we could not use IN clause(grepped in SO threads.)

                  From other SO threads, we can circumvent this problem using joins or exists clause etc. But they all work if both main table and search data are in the database.

                  E.g
                  User table:
                  firstName, lastName, City
                  

                  Given a list of (firstname, lastName) tuples, I need to get the cities.

                  I can think of following solutions.

                  1

                  Construct a select query like,

                  SELECT city from user where (firstName=x and lastName=y) or (firstName=a and lastName=b) or .....
                  

                  2

                  Upload all firstName, lastName values into a staging table and perform a join between 'user' table and the new staging table.

                  Are there any options for solving this problem and what is the preferred of solving this problem in general?

                  解决方案

                  You could do like this:

                  SELECT city FROM user WHERE (firstName, lastName) IN (('a', 'b'), ('c', 'd'));
                  

                  The sqlfiddle.

                  这篇关于IN 子句中的 SQL 多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Oracle 中调用另一个存储过程 下一篇:ORA-01017 从 9i 客户端连接到 11g 数据库时无效的用户名/密码

                  相关文章

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

                    <bdo id='YiAra'></bdo><ul id='YiAra'></ul>

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

                      <small id='YiAra'></small><noframes id='YiAra'>