有表:
规格尺寸
----
29
31
 :
 :奇数不断扩大如果现在实际用的规格为17一、如何得到可用料清单:
29 1开1
35 1开2
51 1开3二、如何得到最省料的规格
51 --最省料的规格

解决方案 »

  1.   

    declare @a table(A int)
    insert @a select 29
    union all select 31
    union all select 35
    union all select 49
    union all select 51
    union all select 61
    union all select 81
    union all select 97
    union all select 133
    select a % 17 b,a from @a order by b
    select a % 17 b,a into #tmp from @a order by b,a
    select a,省的顺序=(select count(1) from #tmp where b<=c.b) from #tmp c
    drop table #tmp
      

  2.   

    1
    select *,'1开'+cast(floor(规格尺寸/17) as varchar(10)) as 可开料 from 表2
    select top 1 * from 表
    order by 规格尺寸 % 17
      

  3.   

    2如果最省的有多个,要一起查出select * from 表
    where 规格尺寸 % 17=(select min(规格尺寸 % 17) from 表)
      

  4.   

    1
    select *,'1开'+rtrim(规格尺寸/17) 可开料 from 表2
    select top 1 * from 表
    order by (规格尺寸 % 17)/(规格尺寸/17)
      

  5.   

    规格尺寸都为int时 相除只保留整数位
    最省应该是余料 除以 开数
      

  6.   

    最省应该是余料 除以 开数如果最省的有多个,要一起查出select * from 表
    where 1.0*(规格尺寸 % 17)/floor(规格尺寸/17)=(select min(1.0*(规格尺寸 % 17)/floor(规格尺寸/17)) from 表)
      

  7.   

    declare @a table(A int)
    insert @a select 29
    union all select 31
    union all select 35
    union all select 49
    union all select 51
    union all select 61
    union all select 81
    union all select 97
    union all select 133select  A as b  from @f order by (A%17)
    这样不可以????
      

  8.   

    declare @a table(A int)
    insert @a select 29
    union all select 31
    union all select 35
    union all select 49
    union all select 51
    union all select 61
    union all select 81
    union all select 97
    union all select 133select  top 1 A from @f order by (A%17),A/17先考虑余数,在考虑开数,取第一个!
    感觉大家考虑的太多!!看问题复杂化拉!
      

  9.   

    注意
    (A%17),A/17 都是整数(A%17)/(A/17)也是整数操作,参考冒牌的答案
      

  10.   

    不好意思,这两天在家没有网上。先感谢大家!但问题一中,我要的可用物料清单是:
    1开1耗料最少的
    1开2耗料最少的
    1开3耗料最少的
    ::请虎虎,冒牌再出手。TKS!
      

  11.   

    select 规格尺寸,'1开'+rtrim(规格尺寸/17) 可开料 from 表 A
    where not exists(select 1 from 表 where 规格尺寸/17=A.规格尺寸/17 and 规格尺寸%17<A.规格尺寸%17)