不同的选择查询ms sql 2005 [英] Distinct selection query ms sql 2005
本文介绍了不同的选择查询ms sql 2005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张表和记录如下:
表名: tbl_post
列: Id,Title,ep
表中的记录:
Id Title Ep
1 恐怖 4
2 现实 6
3 Sci-Fi 3
4 恐怖 7
5 浪漫 8
6 恐怖 2
等......
我只是想把它显示为
<前lang =SQL> Id标题Ep
1 恐怖 4
2 现实 6
3 科幻 3
5 浪漫 8
等等(取消所有其他重复的标题)
我尝试了不同但没有用。
请建议我一些查询(ms-sql)
解决方案
试试这个...
发布
AS
(
SELECT Id,Title,ep,
row_number() over ( partition by 标题订单 by Id) as rowid
from tbl_post
)
SELECT *
FROM 发布其中 rowid = 1 ;
问候,
GVPrabu
选择*来自tbl_post其中的标题(选择区别(标题)来自tbl_post)
I have a table and records as like this:
Table name: tbl_post
Columns: Id, Title,ep
records in the table:
Id Title Ep
1 Horror 4
2 Reality 6
3 Sci-Fi 3
4 Horror 7
5 Romance 8
6 Horror 2
and so on...
I just want to show it as
Id Title Ep
1 Horror 4
2 Reality 6
3 Sci-Fi 3
5 Romance 8
and so on (eliminating all the other repeating title)
I have tried distinct but no use.
Please suggest me some queries (ms-sql)
解决方案
Hi,
Try this...
with Post AS ( SELECT Id, Title,ep, row_number() over (partition by Title order by Id) as rowid from tbl_post ) SELECT * FROM Post where rowid = 1;
Regards,
GVPrabu
Select * From tbl_post Where Title in(Select Distinct(Title) From tbl_post )
这篇关于不同的选择查询ms sql 2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文