日期:2014-05-18  浏览次数:20462 次

应该做像百度新闻那样查询新闻,还取出相同新闻标题的行数
ID
Title
Author
Content

怎么只取出标题不重复的文章呢?还有,能不能像百度这样统计出相同的标题数量:N条相同新闻

------解决方案--------------------
SQL code

declare @t table 
(id int,title varchar(2),author varchar(5),[content] varchar(3))
insert into @t
select 1,'a1','aaa','sss' union all
select 2,'a1','abvcv','sss' union all
select 3,'a2','nkjks','sss' union all
select 4,'a2','asdf','sss' union all
select 5,'a3','aaa','ss'

--得到title不重复的记录
select * from @t t where id=(
select min(id) from @t where title=t.title)
/*
id          title author content
----------- ----- ------ -------
1           a1    aaa    sss
3           a2    nkjks  sss
5           a3    aaa    ss
*/

------解决方案--------------------
SQL code

declare @t table 
(id int,title varchar(2),author varchar(5),[content] varchar(3))
insert into @t
select 1,'a1','aaa','sss' union all
select 2,'a1','abvcv','sss' union all
select 3,'a2','nkjks','sss' union all
select 4,'a2','asdf','sss' union all
select 5,'a3','aaa','ss'

--统计相同标题的条数
select title,条数=count(1) from @t t group by title
/*
title 条数
----- -----------
a1    2
a2    2
a3    1   
*/

------解决方案--------------------
探讨
ID
Title
Author
Content

怎么只取出标题不重复的文章呢?还有,能不能像百度这样统计出相同的标题数量:N条相同新闻