我建了一个视图,怎么从符合条件的记录中每个ID只选一条出来?
结构:
id company_name name flag7 test1 2 1
8 test2 3 1
9 test3 4 1
9 test3 3 1
10 test4 5 1
11 test5 null 1
符合flag=1条件的记录有5条
其中id=9的有两条记录
但我想在flag=1的查询语句里返回id=9的一条记录及:
id company_name name flag7 test1 2 1
8 test2 3 1
9 test3 4 1
10 test4 5 1
11 test5 null 1至于id=9的两条记录里随便拿一条都行
当然能加上条件选择一条更好
该怎么做啊
结构:
id company_name name flag7 test1 2 1
8 test2 3 1
9 test3 4 1
9 test3 3 1
10 test4 5 1
11 test5 null 1
符合flag=1条件的记录有5条
其中id=9的有两条记录
但我想在flag=1的查询语句里返回id=9的一条记录及:
id company_name name flag7 test1 2 1
8 test2 3 1
9 test3 4 1
10 test4 5 1
11 test5 null 1至于id=9的两条记录里随便拿一条都行
当然能加上条件选择一条更好
该怎么做啊
解决方案 »
- 能否用web application 实现?
- ************晕死呀,哪位大侠帮我写一段产生随机数的代码呀。在线等*****************
- 100分求一个功能齐全的datagrid例子,注意要WIN FORM,C#的哦~明天中午结帖,大家抓紧抢分~~~~~提供连接地址也可以
- 为何新建项目(控制台)时,VS.NET就自己退出了?
- winform里面pictureBox控件有没有image属性改变时的事件。
- 请教关于访问ArrayList中元素的问题
- 有关Array的问题,提问有些罗嗦,请海涵!!!!
- WebRequest WReq=WebRequest.Create()中的字符串该怎么使用?
- 关于bmp的保存问题?
- C# wpf问题,win7上运行没有界面,win10上启动正常
- 如何提取一个图片中的图形?图形是单一色的!谢谢!
- 讨教一个报错,c#写的程序无法浏览。
select * from tb a where a.flag=1 and not exists(select 1 from tb b where a.Id=b.Id and a.name<b.name)
--找name最小的。
没看清需求
select distinct company_name from urtable where flag = 1
不过为什么连ID都可以重复呢?
不行
我要把name列也一起输出的
and company_name exists(select distinct company_name from urtable)
and company_name exists(select distinct company_name from urtable )
and [name] exists(select min([name]) from urtable group by [company_name])
select distinct * from 视图
用 distinct
select distinct company_name, name,flag from 视图