[SQL ] 如何求出单行多栏的余数? (已自行解决)

楼主: Severine (赛非茵)   2014-07-28 15:53:40
系统 : SQL Azure (同SQL2012)
DECLARE @Test Table(
SN int,
No1 int,
No2 int,
No3 int,
No4 int,
No5 int)
Insert into @Test Values
(1,10,20,31,40,55),
(2,20,18,34,42,51),
(3,11,23,31,40,52)
select *
from @test
请问如何算出每栏的余数(mod 2)并做单行统计呢? 谢谢~
ASP.NET的方法我会 但是SQL真是没头绪..
希望呈现如下
SN 单数 双数
1 2 3
2 1 4
3 3 2
谢谢..
解法
select (no1%2 + no2%2 + no3%2 + no4%2 + no5%2) ,
5 - (no1%2 + no2%2 + no3%2 + no4%2 + no5%2)
from @test

Links booklink

Contact Us: admin [ a t ] ucptt.com