菜鸟求知:找不同行

wxshzf 2003-05-09 10:47:40
我有一张表如下:
telNo xcode money
83562387 1 34
83562388 2 54
83562389 1 37
83562390 3 44
83562391 1 47
83562392 2 34
83562393 1 56
83562394 3 12
83562395 1 36
我想得到按xcode为1,2,3的不同行,如果用select distinct xcode,仅能得到
xcode
1
2
3
但我要得到的一整行,如
83562387 1 34
83562388 2 54
83562390 3 44
...全文
53 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sasacat 2003-05-09
  • 打赏
  • 举报
回复
select top 1 * from table where xcode in(select distinct xcode form table)
米多 2003-05-09
  • 打赏
  • 举报
回复
不知这个是否可以:
select max(telno) as telNo,xcode,max(money) as money
from table
group by xcode
愉快的登山者 2003-05-09
  • 打赏
  • 举报
回复
select * from yourtable as A
where telNo = (select min(telNo) from yourtable where xcode = A.xcode)
wxshzf 2003-05-09
  • 打赏
  • 举报
回复
如果xcode的值有多个呢?总不能用union写多个语句吧?我只关心xcode唯一,而telno与money则仅带着,其值大小及是否唯一并不重要
psxfghost 2003-05-09
  • 打赏
  • 举报
回复
更保险一点的:
select top 1 * from table where xcode =1 order by telNo
union
select top 1 * from table where xcode =2 order by telNo
union
select top 1 * from table where xcode =3 order by telNo

^_^
psxfghost 2003-05-09
  • 打赏
  • 举报
回复
这是你要实现的吗???
select telNo,xcode,min(money) as money from table where xcode=1 union
select telNo,xcode,max(money) as money from table where xcode=2 union
select telNo,xcode,max(money) as money from table where xcode=3
sasacat 2003-05-09
  • 打赏
  • 举报
回复
select top 1 * from table where xcode =1
union
select top 1 * from table where xcode =2
union
select top 1 * from table where xcode =3

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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