免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2942 | 回复: 8
打印 上一主题 下一主题

这个数据库语句怎么写? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-30 21:41 |只看该作者 |倒序浏览
col1  col2
  1       5
  1       3
  1       4
  2       1
  2       3
  2       4
  3       2
  3       2

执行语句出来是这样
col1  col2
1       3
2       1
3       2


就是在相同的col1中取且只取一个最小的col2

论坛徽章:
1
白银圣斗士
日期:2015-11-23 08:33:04
2 [报告]
发表于 2008-05-30 23:00 |只看该作者
折腾了一下,纯用sql没折腾出来!倒是用PB datawindow 两三分钟就折腾出来了.

论坛徽章:
0
3 [报告]
发表于 2008-05-31 18:49 |只看该作者
select col1, min(col2) from ??? group by col1

论坛徽章:
0
4 [报告]
发表于 2008-05-31 21:33 |只看该作者
select distinct table_name.* from table_name,(select min(col2) as min_col2 from table_name group by col1) as min_col2_table where table_name.col2=min_col2_table.min_col2;

论坛徽章:
0
5 [报告]
发表于 2008-05-31 23:22 |只看该作者
:wink: 同上个表 3楼的就可以了吧。

论坛徽章:
0
6 [报告]
发表于 2008-06-02 09:14 |只看该作者
Assume your table name is test
then the correct sql statement is as follows.
select distinct a.* from test as a where a.col2 = (select min(b.col2) from test as b where a.col1 = b.col1);

论坛徽章:
0
7 [报告]
发表于 2008-06-02 13:17 |只看该作者
原帖由 yueliangdao0608 于 2008-6-2 09:14 发表
Assume your table name is test
then the correct sql statement is as follows.
select distinct a.* from test as a where a.col2 = (select min(b.col2) from test as b where a.col1 = b.col1);


哈哈,这种程度还不够,再加几列,取出对应行的相关列

于是传说中的月经贴出现了。

[ 本帖最后由 sunnyfun 于 2008-6-2 13:20 编辑 ]

论坛徽章:
0
8 [报告]
发表于 2008-06-02 17:30 |只看该作者
原帖由 sunnyfun 于 2008-6-2 13:17 发表


哈哈,这种程度还不够,再加几列,取出对应行的相关列

于是传说中的月经贴出现了。



Menstrual post.

论坛徽章:
0
9 [报告]
发表于 2008-06-07 11:16 |只看该作者

回复 #7 sunnyfun 的帖子

研究研究而已,用程序过滤一下还快一点
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP