select left(title,LEN(title)-1),flag from table group by left(title,LEN(title)-1),flag
select left(title,LEN(title)-1) from table group by left(title,LEN(title)-1)
什么数据库?如果是SQL server,试试这样:SELECT TOP 1 title,flag FROM table where title like '%冰河世纪%' ORDER BY NEWID()SELECT TOP 1 title,flag FROM table where title like '%天堂口%' ORDER BY NEWID()得选择两次
假定表名是table select * from ((select top 1 * from table where title like '%冰河世纪%') or (select top 1 * from table where title like '%天堂口%' ))
create table tb(title varchar(20), flag varchar(10)) insert into tb select '冰河世纪1','冰河' union all select '冰河世纪2','冰河' union all select '冰河世纪3','冰河' union all select '天堂口1 ','天堂' union all select '天堂口2 ','天堂' union all select '天堂口3 ','天堂' select * from tb t where title=(select top 1 title from tb where flag=t.flag order by newid())
group by left(title,LEN(title)-1),flag
group by left(title,LEN(title)-1)
ORDER BY NEWID()SELECT TOP 1 title,flag FROM table where title like '%天堂口%'
ORDER BY NEWID()得选择两次
select * from ((select top 1 * from table where title like '%冰河世纪%') or (select top 1 * from table where title like '%天堂口%' ))
insert into tb select
'冰河世纪1','冰河' union all select
'冰河世纪2','冰河' union all select
'冰河世纪3','冰河' union all select
'天堂口1 ','天堂' union all select
'天堂口2 ','天堂' union all select
'天堂口3 ','天堂' select
*
from
tb t
where
title=(select top 1 title from tb where flag=t.flag order by newid())
能不能想办法,通过多flag分组,然后在每组中提取一行数据
你试试不就知道了select
*
from
tb t
where
title=(select top 1 title from tb where flag=t.flag order by newid())