问个sql查询问题。。。。。。

banban1982 2004-11-01 07:34:07
有一个表A
dot1 dot2 distance
1 2 743
1 3 3749
。 。 。
。 。 。
2 1 743
2 3 372
。 。 。
。 。 。


现在要求dot1中相同的情况下distance的最小值,也就是有dot1=1时最小的distance,有dot1=2时最小的distance,是能帮忙写下sql语句,要求字段是dot1,dot2,distance(最小值)
...全文
219 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
leungzhq2000 2004-11-21
  • 打赏
  • 举报
回复
回来看一下,还没有给我加分啊 !~一定是我回答的不好了!!唉,还得努力了!!!
mh_xxw(毛毛) ( ) 谢谢!你应该是再说我的回答吧!这是我第一次接倒别人的表扬!
我会努力的!
我很无聊,!是吧??
呵呵,今天没有事情做,来这里看看!!
mh_xxw 2004-11-19
  • 打赏
  • 举报
回复
另,二楼的回答较好
mh_xxw 2004-11-19
  • 打赏
  • 举报
回复
SELECT dot1,dot2,distance FROM A GROUP BY dot1 ORDER BY distance
fengyeng 2004-11-12
  • 打赏
  • 举报
回复
select tab2.dot1,tab1.dot2,tab2.distance From a as tab1,(select dot1,Min(distance) From a group by dot1 order by dot1) as tab2 where tab1.dot1=tab2.dot1 and tab1.distance=tab2.distance
davorsuker39 2004-11-09
  • 打赏
  • 举报
回复
select distinct a.dot1,a.dot2 ,a.distance from A a, where (select * from A where dot1=a.dot1 and a.distance<=all(select distance from a where dot1=a.dot1))
fengyeng 2004-11-09
  • 打赏
  • 举报
回复
同意楼上!
LAIYANGPJ 2004-11-02
  • 打赏
  • 举报
回复
sele distinct x.dot1 as dot1,x.dot2 as dot2,x.distance as distance from a x,a y where x.dot1=y.dot1 and x.distance<=all(sele distance from a where dot1=x.dot1)
xclzteb 2004-11-02
  • 打赏
  • 举报
回复
“因果网”的用到了临时表
xclzteb 2004-11-02
  • 打赏
  • 举报
回复
在VFP中用“因果网”的能行,如果是SQL语句就用我给出的那个,经过类似表进行了调试通过。
JohnShen 2004-11-02
  • 打赏
  • 举报
回复
没有测试,你先试试:
SELECT dot1,min(distance) as min_distance FROM A into cursor cTemp GROUP BY dot1
Select A.dot1,A.dot2,A.distance From A ;
Left Join cTemp On A.dot1 = cTemp.dot1 And A.distance = cTemp.min_distance;
Where Not(Isnull(A.dot1) Or Empty(A.dot1))
xclzteb 2004-11-02
  • 打赏
  • 举报
回复
这就是你想要的结果,你也可以指定另外的列名。
xclzteb 2004-11-02
  • 打赏
  • 举报
回复
select tab2.dot1,tab1.dot2,tab2.distance From a as tab1,(select dot1,Min(distance) From a group by dot1 order by dot1) as tab2 where tab1.dot1=tab2.dot1 and tab1.distance=tab2.distance
Surpass 2004-11-02
  • 打赏
  • 举报
回复
SELECT dot1,dot2,distance FROM A GROUP BY dot1 ORDER BY distance
itzhiren 2004-11-02
  • 打赏
  • 举报
回复
select dot1,dot2,distance from a group by dot1 order by distance
leungzhq2000 2004-11-01
  • 打赏
  • 举报
回复
可以使用多个语句来进行吗?
如果可以,你可以参考一下这个:(最好在程序中使用了)
sele distinct dot1 from A order by dot1
count to num1
dimension arr1(num1,1)
copy to array arr1
for i=1 to num1
sele * from A where dot1=arr1(i,1) order by distance nowait
count to num2
dimension arr2(num2,3)
copy to array arr2
?arr2(i,1),arr2(i,2),arr2(i,3)
next
这样就能把你想要的结果显示出来。这样你可以解决你想要的东西,比如表形式的结果,其他等等!~


sbw 2004-11-01
  • 打赏
  • 举报
回复
select dot1,dot2,distance from a group by dot1 order by distance desc

2,748

社区成员

发帖
与我相关
我的任务
社区描述
VFP,是Microsoft公司推出的数据库开发软件,用它来开发数据库,既简单又方便。
社区管理员
  • VFP社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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