日期:2014-05-18 浏览次数:20462 次
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 */
------解决方案--------------------
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 */
------解决方案--------------------