SQL语句写法

dtmyou 2003-08-19 09:41:38
table1:
id column1 column2
1 1 4
2 1 5
3 1 6
4 1 7
5 0 1
6 0 3
7 0 2
其中column1为1或0,
要求得到结果
id column1 column2
1 1 4
2 1 5
5 0 1
7 0 2
...全文
20 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hjb111 2003-08-19
  • 打赏
  • 举报
回复
crete index i_index on yourtable(id,column2,column1)
CrazyFor 2003-08-19
  • 打赏
  • 举报
回复
很慢就给ID,COLUMN2,column1字段加索引.
CrazyFor 2003-08-19
  • 打赏
  • 举报
回复
很慢就给ID,COLUMN2,column1字段加索引.
dtmyou 2003-08-19
  • 打赏
  • 举报
回复
多谢,好笨啊我^_^

数据多的话好像很慢,我还是在程序中分别处理好了...
pengdali 2003-08-19
  • 打赏
  • 举报
回复
select * from table1 tem where id in (select top 2 id from table1 where column1=tem.column1 order by column2)
愉快的登山者 2003-08-19
  • 打赏
  • 举报
回复
select * from table1 A
where column2 in (select top 2 column2 from table1 where column1 = A.column1 order by column2)

愉快的登山者


◢◣◢◣◢◣

34,576

社区成员

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

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