作者ChingLan326 (总舵主)
看板Database
标题[SQL ] 「.. 」条件写法
时间Wed Apr 19 10:39:57 2017
资料库名称:MS SQL
资料库版本:2014
内容/问题描述:
资料表如下
AccountID Amount Totaling
---------- -------------------- --------------------
101010 101011..101019
101011 10
101012 20
101013 30
101014 40
101015 50
101016 60
如果Totaling不为空,表示Amount为合计栏位
上表中
AccountID = 101010的Amount为
AccountID between 101011 and 101019 的 Amount 合计
我现在用CHARINDEX去拆Totaling为2个栏位
再用between条件去合计
请问有其他写法吗
觉得资料条件这样设计应该有其他更聪明的写法
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 113.196.173.84
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Database/M.1492569601.A.A03.html
※ 编辑: ChingLan326 (113.196.173.84), 04/19/2017 10:41:09