因为系统调整,要求把_values值全改成30的倍数,如果不是三十倍数的话就近改成30倍数。举例,40就改成30,50就改成60,70改成60,80改成90,100改成90表结构如下:全是int型
id _values
1 30
13 30
19 40
41 30
43 30
47 30
48 30
64 30
69 30
70 80
87 30
89 30
103 190
110 50
113 40
133 30
140 30
148 50
158 30
184 30
208 40
216 160
226 30
243 30
245 30
256 420
285 80
292 30
297 30
304 30
311 30
319 100
322 60
330 30
334 40
344 60
360 30
362 30
375 30
381 30
391 530
394 150
398 100
407 70
421 30
444 31
472 140
475 30
477 30
478 30
488 40
489 60
490 40
494 30
506 30
529 61
530 30
560 30
596 30
597 40
598 30
605 30
619 50
637 40
640 30
651 30
654 30
660 30
669 40
672 30
680 30
686 40
691 50
699 30
709 30
710 50
744 30
748 50
789 30
793 30
801 30
804 100
810 30
822 30
865 30
870 30
882 30
898 30
909 30
912 30
928 30
935 120
936 30
944 30
945 40
960 40
969 30
1026 30
1091 30
1094 30
1096 60
1097 30
1100 30
1125 50
1128 30
1143 30
1152 30
1155 50
1162 130
1166 50
1177 30
1192 40
1199 30
1215 30
1224 30
1238 50
1241 30
1261 30
1270 30
1301 240
1306 30
1312 30
1314 30
1391 40
1392 30
1405 30
1431 30
1434 30
1435 60
1473 30
1474 130
1477 60
1480 30
1520 30
1522 30
1537 140
1544 30
1577 100
1584 30
1589 30
1592 30
1617 30
1624 40
1633 30
1643 30
1674 130
1679 30
1694 30
1698 30
1708 30
1710 30
1717 60
1735 130
1736 50
1744 30
1769 100
1802 30
1806 30
1844 30
1866 30
1874 300
1899 30
1939 30
1944 30
1967 30
1972 30
2007 30
2018 31
2036 360
2045 30
2079 30
2107 50
2117 30
2129 30
2137 30
2140 30
2214 50
2227 30
2253 30
2260 30
2316 70
2317 40
2319 30
2325 30
2329 30
2330 910
2337 30
2343 30
2367 40
2376 30
2377 30
2392 30
2403 30
2419 30
2458 30
2469 30
2471 150
2489 30
2503 30
2509 30
2511 30
2517 30
2520 80
2537 30
2566 50
2571 30
2595 30
2599 90
2607 30
2613 50
2616 40
2628 30
2649 30
2659 30
2663 30
2665 60
2668 30
2670 30
2690 90
2691 30
2713 30
2722 30
2732 30
2745 30
2753 30
2776 30
2783 30
2883 30
2917 30
2937 30
2946 30
2948 30
2958 30
2960 430
2967 30
2973 310
2979 30
2986 30
3002 30
3014 70
3024 70
3045 51
3046 30
3067 100
3084 30
3126 30
3159 30
3169 40
3176 30
3185 30
3204 30
3232 40
3242 60
3247 30
3263 30
3324 70
3336 50
3340 30
3341 30
3352 30
3364 30
3373 30
3377 30
3462 30
3493 140
3501 40
3536 30
3537 100
3552 30
3561 30
3565 60
3586 30
3595 30
3602 30
3616 30
3623 30
3640 50
3659 30
3699 40
3713 60
3747 30
3764 40
3777 30
3799 30
3802 30
3807 30
3890 30
3891 40
3897 30
3902 30
3925 30
3946 30
3949 30
3957 40
3963 30
3978 40
3998 30
4004 50
4038 30
4062 30
4069 30
4070 30
4079 120
4114 30
4121 30
4124 120
4128 270
4174 30
4177 30
4180 30
4182 30
4198 30
4202 30
4220 30
4232 30
4251 30
4255 30
4310 30
4318 30
4331 40
4345 40
4352 50
4357 70
4368 30
4373 100
4377 30
4379 30
4389 70
4398 30
4400 210
4402 30
4420 30
4429 30
4476 30
4482 30
4485 30
4511 60
4521 40
4525 30
4526 40
4527 30
4535 30
4545 60
4550 30
4551 150
4564 40
4565 30
4575 90
4577 30
4595 30
4601 30
4602 30
4606 250
4620 30
4624 30
4642 30
4643 180
4677 30
4685 30
4694 30
4754 30
4755 30
4776 30
4778 50
4788 30
4795 30
4797 30
4800 40
4805 40
4807 30
4841 30
4854 30
4878 30
4901 60
4944 30
4953 30
4980 30
4994 30
4999 30
5007 30
5017 30
5044 40
5051 30
5069 30
5073 30
5102 30
5117 40
5148 30
5170 40
5180 30
5187 30
5196 30
5200 30
5208 30
5215 40
5229 30
5268 52
5289 30
5291 30
5302 52
5305 550
5319 50
5332 30
5342 30
5343 30
5344 30
5352 30
5358 30
5366 30
5370 30
5375 30
5426 51
5427 60
5430 30
5446 30
5448 30
5456 30
5459 50
5465 30
5473 30
5506 30
5519 30
5560 70
5566 30
5576 30
5607 140
5630 30
5635 30
5652 130
5672 150
5698 30
5719 30
5731 30
5756 30
5758 30
5768 40
5779 30
5784 30
5789 30
5803 30
5814 30
5849 30
5889 30
5909 30
5914 50
5928 30
5941 30
5975 30
5981 30
5995 30
6013 30
6016 30
6026 70
6080 30
6082 50
6091 1350
6121 30
6128 40
6148 70
6157 30
6158 30
6166 30
6178 101
6182 30
6200 30
6231 490
6239 30
6245 30
6247 30
6263 30
6287 30
6313 30
6342 30
6368 30
6426 30
6448 30
6462 30
6475 370
6478 40
6556 30
6624 30
6626 30
6629 40
6684 30
6753 80
6761 30
6788 30
6867 80
6894 30
6923 70
6976 80
6984 40
7003 30
7008 30
7016 50
7109 30
7138 30
7183 30
7195 30
7274 30
7290 30
7306 30
7354 30
7360 30
7442 100
7453 30
7473 40
7475 60
7482 360
7527 30
7549 30
7706 90
7717 480
7726 30
7764 30
7783 30
7817 40
7863 30
7902 40
7967 30
8097 30
8148 60
8175 30
8243 30
8245 30
8301 30
8380 40
8381 30
8386 30
8510 30
8579 30
8668 50
8717 50
8784 30
8814 30
8831 40
8863 30
8890 30
8921 30
8940 80
8973 30
8982 30
8993 30
8996 30
9005 30
9019 30
9023 40
9090 30
9099 30
9106 30
9143 280
9149 30
9168 30
9169 30
9208 30
9226 30
9260 30
9261 30
9271 30
9303 30
9317 30
9333 30
9338 30
9339 40
9346 30
9350 230
9351 80
9360 60
9363 40
9364 200
9368 30
9370 30
9375 30
9381 30
9407 30
9409 60
9426 30
9429 30
9438 30
9441 70
9452 50
9484 30
9494 130
9499 30
9501 30
9506 130
9519 30
9521 30
9523 30
9526 80
9536 30
9537 120
9541 30
9545 30
9563 30
9580 30
9593 30
9596 30
9609 30
9629 40
9637 30
9639 180
9643 30
9644 30
9675 40
9681 30
9687 100
9714 30
9720 30
9747 30
9753 30
9756 30
9764 30
9766 30
9768 30
9783 40
9788 30
9789 40
9806 30
9836 30
9840 30
9841 120
9851 30
9866 30
9868 60
9881 30

解决方案 »

  1.   

    declare @tb table(a int,b int)
    insert into @tb select 40,0
    insert into @tb select 50,0
    insert into @tb select 70,0
    insert into @tb select 80,0
    insert into @tb select 100,0update @tb set b=case when a%30>=15 then a/30*30+30 else (a/30+1)*30-30 endselect * from @tba b
    40 30
    50 60
    70 60
    80 90
    100 90
      

  2.   

    取一部分数据来测试,如果都是你列出来的这种格式,可以这样---测试数据---
    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([id] int,[_values] int)
    insert [tb]
    select 1,30 union all
    select 13,30 union all
    select 19,40 union all
    select 41,30 union all
    select 43,30 union all
    select 47,30 union all
    select 48,30 union all
    select 64,30 union all
    select 69,30 union all
    select 70,80 union all
    select 87,30 union all
    select 89,30 union all
    select 103,190 union all
    select 110,50 union all
    select 113,40 union all
    select 133,30 union all
    select 140,30 union all
    select 148,50 union all
    select 158,30 union all
    select 184,30 union all
    select 208,40 union all
    select 216,160 union all
    select 226,30 union all
    select 243,30 union all
    select 245,30 union all
    select 256,420 union all
    select 285,80 union all
    select 292,30 union all
    select 297,30 union all
    select 304,30 union all
    select 311,30 union all
    select 319,100
     
    ---查询---
    select 
      id, 
      case _values%30 when 10 then _values-10 when 20 then _values+10 else _values end  as _values
    from [tb]---结果---
    id          _values     
    ----------- ----------- 
    1           30
    13          30
    19          30
    41          30
    43          30
    47          30
    48          30
    64          30
    69          30
    70          90
    87          30
    89          30
    103         180
    110         60
    113         30
    133         30
    140         30
    148         60
    158         30
    184         30
    208         30
    216         150
    226         30
    243         30
    245         30
    256         420
    285         90
    292         30
    297         30
    304         30
    311         30
    319         90(所影响的行数为 32 行)
      

  3.   

    用case wnen.可以结帖了.哈哈.
      

  4.   

    create table [tb]([id] int,[value] int)
    insert [tb]
    select 1,30 union all
    select 13,30 union all
    select 19,40 union all
    select 41,30 union all
    select 43,30 union all
    select 47,30 union all
    select 48,30 union all
    select 64,30 union all
    select 69,30 union all
    select 70,80 union all
    select 87,30 union all
    select 89,50 
    goselect id , 
           old_value = value ,
           new_value = (case when value%30 >= 15 then (value/30 + 1) * 30 else (value/30) * 30 end)
    from tbdrop table tb/*
    id          old_value   new_value   
    ----------- ----------- ----------- 
    1           30          30
    13          30          30
    19          40          30
    41          30          30
    43          30          30
    47          30          30
    48          30          30
    64          30          30
    69          30          30
    70          80          90
    87          30          30
    89          50          60(所影响的行数为 12 行)
    */
      

  5.   

    _value可能出现 101,105,108这些都有可能嘚。。
      

  6.   


    能不能给条完整的,执行完了,所有_value字段就全自动更新成我说的那个标准、。
      

  7.   


    create table [tb]([id] int,[value] int)
    insert [tb]
    select 1,30 union all
    select 13,30 union all
    select 19,40 union all
    select 41,30 union all
    select 43,30 union all
    select 47,30 union all
    select 48,101 union all
    select 64,105 union all
    select 69,108 union all
    select 70,80 union all
    select 87,30 union all
    select 89,50 
    goselect id , 
           old_value = value ,
           new_value = (case when value%30 >= 15 then (value/30 + 1) * 30 else (value/30) * 30 end)
    from tbdrop table tb/*
    id          old_value   new_value   
    ----------- ----------- ----------- 
    1           30          30
    13          30          30
    19          40          30
    41          30          30
    43          30          30
    47          30          30
    48          101         90
    64          105         120
    69          108         120
    70          80          90
    87          30          30
    89          50          60(所影响的行数为 12 行)
    */你只需要这段即可.
    select id , 
           old_value = value ,
           new_value = (case when value%30 >= 15 then (value/30 + 1) * 30 else (value/30) * 30 end)
    from tb
      

  8.   

    这个是select出来的,请问怎么执行update更新呢???
      

  9.   


    update 表名 set _values=floor(round(_values /3.0,-1))*3