English 中文(简体)
2008年Sql服务器使用独特和秩序[封闭]
原标题:Use of Distinct & Order by in Sql Server 2008 [closed]
问题回答

页: 1 服务器只允许你<代码>。 在<代码>DISTINCT清单中按列的>栏目分列,因为否则,非选列的栏目可能会在交回结果中对某一行进行不止一次的价值测绘。

如果你知道,情况并非如此,你可以使用计算结果。

;WITH CTE
     AS (SELECT DISTINCT foo,
                         bar
         FROM   T)
SELECT foo
FROM   CTE
ORDER  BY bar  

如果由于实际存在多个可能的<条码>、条码/条码>值,每条<条码> 那么,你需要毫不含糊地告诉它什么价值用于秩序。 例如,采用<代码>GROUP BY。

SELECT foo
FROM T
GROUP BY foo
ORDER BY MIN(bar)




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签