SQL里面用case when的问题。。。。
时间:2011-11-30
来源:互联网
这4张表:
Provider: ProId(供应商Id、主键)、Name(供应商名字)
GoodsInfo: GoodsId(商品id、主键)、Name(商品名称)、GuiGe(规格)、Unit(产地)、ProId(供应商Id、外键) 、memo
BuyInfo: BuyId(订单编号、主键)、ProId(供应商Id、外键)、DateOfBuy(采购日期、datetime类型)
BuyDetails: BuyId(订单编号、外键)、GoodsId(商品id、外键)、Count(数量)
作者: abcjunq 发布时间: 2011-11-30
作者: yhui1989love 发布时间: 2011-11-30

解释得太混乱了。
作者: fredrickhu 发布时间: 2011-11-30
作者: a1247449520 发布时间: 2011-11-30
select b.GoodsId, b.Name, b,GuiGe, b.Unit, case memo when 'a' then sum(Price*d.[count])/sum(d.[count]) when 'b' then c.DateOfBuy else set 'null' end as cost from Provider as a ,goodsInfo as b ,BuyInfo as c ,BuyDetails as d where d.GoodsId=b.GoodsId and d.BuyId=c.BuyId and b.ProId=a.ProId and DateOfBuy between '起始时间' and '结束时间'
大概的是这个意思?
作者: houyajin 发布时间: 2011-11-30

最好能上点数据!
作者: abclm 发布时间: 2011-11-30
--假设price是 GoodsInfo 表中的列 select b.GoodsId,b.Name,b.GuiGe,b.Unit,a.name, cost=(select sum(c.Price*e.count)/sum(d.count) from goodsId c inner join buydetails d on c.goodsid=d.goodsid inner join buyinfo e on d.buyid=e.buyid where c.goodsid=b.goodsid and datediff(d,e.dateofbuy,getdate())=(case when c.memo='A' then datediff(d,e.dateofbuy,getdate()) else 30 end)) from goodsinfo b inner join provider a on a.proid=b.proid
作者: qianjin036a 发布时间: 2011-11-30
SQL code
--假设price是 GoodsInfo 表中的列 select b.GoodsId,b.Name,b.GuiGe,b.Unit,a.name, cost=(select sum(c.Price*d.count)/sum(d.count) from goodsId c inner join buydetails d on c.goodsid=d.goodsid inner join buyinfo e on d.buyid=e.buyid where c.goodsid=b.goodsid and datediff(d,e.dateofbuy,getdate())=(case when c.memo='A' then datediff(d,e.dateofbuy,getdate()) else 30 end)) from goodsinfo b inner join provider a on a.proid=b.proid
作者: qianjin036a 发布时间: 2011-11-30
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28