求教一个查询的 sql语句

lx_thunder 2004-06-23 06:58:37
表中记录如下,
字段1 字段2 字段3 字段4
aa 1 xx xx
aa 5 xx xx
bb 1 .. ..
cc 1 .. ..
cc 5 .. ..
dd 1 .. ..
ee 1 .. ..
ff 1 .. ..
ff 5 .. ..
希望查询出的记录集,如下:
字段1 字段2 字段3 字段4
aa 1 xx xx
cc 1 .. ..
ff 1 .. ..
请问如何些sql??
恳请高手指点,谢谢~~!在线等候!!
...全文
68 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
pisces007 2004-06-23
  • 打赏
  • 举报
回复
select * from yourtable o
where 字段2 in
(
select 字段2 from yourtable i where i.字段1=o.字段1
and i.字段2 =(select min(字段2) from yourtable
where 字段1=i.字段1 group by 字段1)
group by i.字段2 having count(i.字段1)>1
)
qiliu 2004-06-23
  • 打赏
  • 举报
回复
试试这个
select 字段1, min(字段2), 字段3,字段4 from test
where ascII(left(字段1,1))%2=1 group by 字段1
pisces007 2004-06-23
  • 打赏
  • 举报
回复
select 字段1,min(字段2),字段3,字段4
from yourtable where 字段1 in
(select 字段1 from yourtable group by 字段1
having count(字段1 )>1)

viptiger 2004-06-23
  • 打赏
  • 举报
回复
SELECT IDENTITY(int, 1,1) AS ID_Num
INTO #NewTable
FROM (select * from YouTable
where 字段1 in(select 字段1 from YourTable
group by 字段1
having count(*) > 1)) as b
select * from #NewTable
where ID_Num in (select min(ID_Num) from #NewTable
group by 字段1)
viptiger 2004-06-23
  • 打赏
  • 举报
回复
SELECT IDENTITY(int, 1,1) AS ID_Num
INTO #NewTable
FROM (select * from YouTable
where 字段1 in(select 字段1 from YourTable
group by 字段1
having count(*) > 1)as a) as b
select * from #NewTable
where ID_Num in (select min(ID_Num) from #NewTable
group by 字段1)
kunp 2004-06-23
  • 打赏
  • 举报
回复
select 字段1, min(字段2), 字段3,字段4 from test group by 字段1

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧