复杂分组问题,现实中遇到的问题

qz521dotnet 2010-07-06 09:00:00
有表A(窗高(int),窗宽(int)) 存储的是窗的高度和宽度,现在要把表A中,高度或者宽度在5毫米之内的数据分组,然后求出分组后的最小窗高和窗宽,
10,12
15,13
16,17

这样的三组数据就会被分成两组 的到的结果就是
10,12
16,17
...全文
109 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
qz521dotnet 2010-07-08
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 dla001 的回复:]
10 12
14 13
16 13

怎么分组?结果是?
10 12
16 13
还是
10 12
14 13
[/Quote]

这两种结果都正确
qz521dotnet 2010-07-08
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 junge2150501 的回复:]
10 12 等 是表示毫米吗?
[/Quote]
是的
qz521dotnet 2010-07-08
  • 打赏
  • 举报
回复
这个没有明确的要求,这两种结果都是正确的。
dla001 2010-07-06
  • 打赏
  • 举报
回复
10 12
14 13
16 13

怎么分组?结果是?
10 12
16 13
还是
10 12
14 13
qz521dotnet 2010-07-06
  • 打赏
  • 举报
回复
才能分到一组
qz521dotnet 2010-07-06
  • 打赏
  • 举报
回复
也就是说必须满足两组数据的宽度在5毫米之内并且高度也在5毫米之内
qz521dotnet 2010-07-06
  • 打赏
  • 举报
回复
可能我没表达清楚高度或者宽度在5毫米之内这条不是说没一组数据的,而是所有数据的。
黄_瓜 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 guguda2008 的回复:]

SQL code
--改一下小爱的,如果采用分请给3L
if object_id('tempdb.dbo.#tb') is not null drop table #tb
go
create table #tb([a] int,[b] int)
insert #tb
select 10,12 union all
select 15,13 union all
select 16,17

----……
[/Quote]
看成要最大的了
guguda2008 2010-07-06
  • 打赏
  • 举报
回复
--改一下小爱的,如果采用分请给3L
if object_id('tempdb.dbo.#tb') is not null drop table #tb
go
create table #tb([a] int,[b] int)
insert #tb
select 10,12 union all
select 15,13 union all
select 16,17

--------------------------------查询开始------------------------------

select * from #tb t where not exists(select 1 from #tb where [a]%5=t.[a]%5 and b<t.b)
/*
10 12
16 17
*/
黄_瓜 2010-07-06
  • 打赏
  • 举报
回复
--> 测试数据:#tb
if object_id('tempdb.dbo.#tb') is not null drop table #tb
go
create table #tb([a] int,[b] int)
insert #tb
select 10,12 union all
select 15,13 union all
select 16,17

--------------------------------查询开始------------------------------

select * from #tb t where not exists(select 1 from #tb where [a]%5=t.[a]%5 and b>t.b)
/*
a b
----------- -----------
15 13
16 17

(2 行受影响)


*/
qz521dotnet 2010-07-06
  • 打赏
  • 举报
回复
自己顶
qz521dotnet 2010-07-06
  • 打赏
  • 举报
回复
自己顶
jsjwlxh 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 dla001 的回复:]
10 12
14 13
16 13

怎么分组?结果是?
10 12
16 13
还是
10 12
14 13
[/Quote]


UP
感觉也是哦
同光和尘 2010-07-06
  • 打赏
  • 举报
回复
10 12 等 是表示毫米吗?

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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