<tfoot id='IWer4'></tfoot>

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

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

    1. <legend id='IWer4'><style id='IWer4'><dir id='IWer4'><q id='IWer4'></q></dir></style></legend>
        <bdo id='IWer4'></bdo><ul id='IWer4'></ul>

      1. 在一列上选择 DISTINCT

        时间:2023-07-17
        <i id='NHidG'><tr id='NHidG'><dt id='NHidG'><q id='NHidG'><span id='NHidG'><b id='NHidG'><form id='NHidG'><ins id='NHidG'></ins><ul id='NHidG'></ul><sub id='NHidG'></sub></form><legend id='NHidG'></legend><bdo id='NHidG'><pre id='NHidG'><center id='NHidG'></center></pre></bdo></b><th id='NHidG'></th></span></q></dt></tr></i><div id='NHidG'><tfoot id='NHidG'></tfoot><dl id='NHidG'><fieldset id='NHidG'></fieldset></dl></div>
      2. <tfoot id='NHidG'></tfoot>
              <legend id='NHidG'><style id='NHidG'><dir id='NHidG'><q id='NHidG'></q></dir></style></legend>

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

                  <tbody id='NHidG'></tbody>

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

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

                  问题描述

                  使用 SQL Server,我有...

                  Using SQL Server, I have...

                  ID  SKU     PRODUCT
                  =======================
                  1   FOO-23  Orange
                  2   BAR-23  Orange
                  3   FOO-24  Apple
                  4   FOO-25  Orange
                  

                  我想要

                  1   FOO-23  Orange
                  3   FOO-24  Apple
                  

                  这个查询并没有让我到达那里.如何仅对一列选择 DISTINCT?

                  This query isn't getting me there. How can I SELECT DISTINCT on just one column?

                  SELECT 
                  [ID],[SKU],[PRODUCT]
                  FROM [TestData] 
                  WHERE ([PRODUCT] = 
                  (SELECT DISTINCT [PRODUCT] FROM [TestData] WHERE ([SKU] LIKE 'FOO-%')) 
                  ORDER BY [ID]
                  

                  推荐答案

                  假设您使用的是 SQL Server 2005 或更高版本,您可以将 CTE 与 ROW_NUMBER() 一起使用:

                  Assuming that you're on SQL Server 2005 or greater, you can use a CTE with ROW_NUMBER():

                  SELECT  *
                  FROM    (SELECT ID, SKU, Product,
                                  ROW_NUMBER() OVER (PARTITION BY PRODUCT ORDER BY ID) AS RowNumber
                           FROM   MyTable
                           WHERE  SKU LIKE 'FOO%') AS a
                  WHERE   a.RowNumber = 1
                  

                  这篇关于在一列上选择 DISTINCT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 SQL Server 中将表从一个数据库复制到另一个数据库 下一篇:用于在 SQL Server 中存储 ip 地址的数据类型

                  相关文章

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

                    <small id='8FOKh'></small><noframes id='8FOKh'>