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

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

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

    1. <tfoot id='EEyFm'></tfoot>

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

        仅对一列使用不同的 SQL 查询多列

        SQL Query Multiple Columns Using Distinct on One Column Only(仅对一列使用不同的 SQL 查询多列)

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

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

              • <legend id='hJ5nJ'><style id='hJ5nJ'><dir id='hJ5nJ'><q id='hJ5nJ'></q></dir></style></legend>
                1. <small id='hJ5nJ'></small><noframes id='hJ5nJ'>

                  <tfoot id='hJ5nJ'></tfoot>
                    <tbody id='hJ5nJ'></tbody>

                  本文介绍了仅对一列使用不同的 SQL 查询多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试编写一个 SQL 查询,该查询从表中选择多个列,并且仅在一列上使用不同的运算符.

                  I am trying to write a SQL query that selects multiple columns from a table with the distinct operator on one column only.

                  表格很简单.列是:

                  tblFruit_ID, tblFruit_FruitType, tblFruit_FruitName
                  int          NVarChar            Text
                  

                  我正在尝试选择所有具有相应 tblFruit_ID 的 tblFruit_FruitType.

                  I am trying to select all the tblFruit_FruitType with their corresponding tblFruit_ID.

                  我试过了:

                  Select Distinct(tblFruit_FruitType), tblFruit_ID FROM tblFruit
                  

                  -返回所有结果,而不仅仅是不同的

                  -Returns all results, not just distinct

                  Select tblFruit_FruitType, tblFruit_ID FROM tblFruit Group By tblFruit_FruitType
                  

                  -列 tblFruit_ID 的错误在选择列表中无效,因为它不包含在聚合函数或 GROUP BY 子句中.

                  -Errors with Column tblFruit_ID is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

                  Select tblFruit_FruitType, tblFruit_ID FROM tblFruit Group By tblFruit_FruitType, tblFruit_ID
                  

                  -返回所有结果,而不仅仅是不同的

                  -Returns all results, not just distinct

                  我也查看了这些类似的帖子,但没有任何工作:(

                  I also checked out these similar posts and could not get anything to work :(

                  mySQL 选择一列 DISTINCT,与对应的其他列

                  SQL Server Distinct Union 用于一列

                  希望这是回答问题的足够信息.

                  Hopefully this is enough information for an answer.

                  感谢您的宝贵时间!

                  编辑(示例数据和所需结果)

                  EDIT (Sample Data and Desired Results)

                  tblFruit_ID, tblFruit_FruitType, tblFruit_FruitName
                  int          NVarChar            Text
                  1            Citrus              Orange
                  2            Citrus              Lime
                  3            Citrus              Lemon
                  4            Seed                Cherry
                  5            Seed                Banana
                  

                  结果:

                  1            Citrus
                  4            Seed
                  

                  推荐答案

                  select * from tblFruit where
                  tblFruit_ID in (Select max(tblFruit_ID) FROM tblFruit group by tblFruit_FruitType)
                  

                  这篇关于仅对一列使用不同的 SQL 查询多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  sql group by versus distinct(sql group by 与不同)
                  How to return a incremental group number per group in SQL(如何在SQL中返回每个组的增量组号)
                  1. <legend id='QjETe'><style id='QjETe'><dir id='QjETe'><q id='QjETe'></q></dir></style></legend><tfoot id='QjETe'></tfoot>
                        <tbody id='QjETe'></tbody>

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

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