如何在没有主键的MSSQL表中搜索重复记录并按列排序?
我从 SQL 表中获取前 20 条记录
我的 MS SQL 表中有一个“状态”列,其中有一些数字数据,
在我的例子中,在获得城市和国家/地区的重复结果后,我跳过了 C# 函数中的数字记录,
例如,如果我跳过州数字数据,“洛杉矶”、“委内瑞拉”就会重复
如果“州”字段包含数字,如何使用 SQL 脚本删除/删除重复条目
我还想按降序排列从国家“美国”获取热门记录
我写的查询如下:-
Declare @sCity varchar(100),
SELECT Top 20 City,State,Country
FROM
[dbo].[Locations]
WHERE
City like @sCity+'%'
ORDER BY
[dbo].[AllWorldLocations].Country DESC,
[dbo].[AllWorldLocations].STATE ASC,
[dbo].[AllWorldLocations].City ASC
我的表是这样的
我想要按国家/地区降序排列记录
Los Angeles California United States
Los Angeles Texas United States
Los Angeles Subdivision Texas United States
I getting top 20 record from SQL Table
There is a column State in My MS SQL Table there are some numeric data,
In my case I skipped numeric records from C# function after I am getting duplicate results of City and Country,
for example 'Los Angeles','Venezuela' coming duplicates if I skipped state numeric data
How to remove/delete duplicate entries if the 'state' field contains numeric using SQL scripts
also I want to get top records from the Country 'United states' in Descending order
I wrote query as below:-
Declare @sCity varchar(100),
SELECT Top 20 City,State,Country
FROM
[dbo].[Locations]
WHERE
City like @sCity+'%'
ORDER BY
[dbo].[AllWorldLocations].Country DESC,
[dbo].[AllWorldLocations].STATE ASC,
[dbo].[AllWorldLocations].City ASC
my table is like that
I want to get records descending order by country
Los Angeles California United States
Los Angeles Texas United States
Los Angeles Subdivision Texas United States
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查找重复项:
http://petefreitag.com/item/169.cfm
过滤数字字符:
http://msdn.microsoft.com/en-us/library/ms186272.aspx
Find duplicates:
http://petefreitag.com/item/169.cfm
Filter numeric characters:
http://msdn.microsoft.com/en-us/library/ms186272.aspx