作者Severine (赛非茵)
看板Database
标题[SQL ] 如何求出单行多栏的余数?
时间Mon Jul 28 15:53:40 2014
系统 : 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
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 220.138.48.157
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Database/M.1406534022.A.108.html
※ 编辑: Severine (220.138.48.157), 07/28/2014 16:09:39
※ 编辑: Severine (220.138.48.157), 07/28/2014 16:23:17