如何从唯一 id 基础 varchar 数据类型中获取值
Posted
技术标签:
【中文标题】如何从唯一 id 基础 varchar 数据类型中获取值【英文标题】:How to get value from unique id basis varchar datatype 【发布时间】:2018-05-19 10:15:23 【问题描述】:我有以下疑问;你能帮我吗?我有 comboAmount 和 TotalPrice,我想将 TotalPrice + Combo Amount 添加到 newComboAmount 中,但由于我的 ComboUniqueId 与其他不同,因此显示错误结果,请查看下图并查询
SELECT
CAST(CASE
WHEN a.TotalPrice != 0
THEN 1
ELSE 0
END AS bit) AS CheckOtherPrice,
a.OrderDetailId, a.ItemId,
b.ItemCode, b.ItemName,
e.GroupName,
a.Quantity, a.Price, a.TotalPrice,
a.OrderId, ISNULL(a.ComboId, 0) ComboId,
(a.ComboAmount + SUM(a.TotalPrice) OVER (ORDER BY a.OrderDetailId)) AS new_comboamount,
a.ComboGroupId, a.ComboAmount, a.ComboUniqueId,
c.ComboName, d.GroupName ComboGroupName,
a.OfferMasterId
FROM
OrderDetail a
INNER JOIN
ItemMaster b ON a.ItemId = b.ItemId AND a.OrderId IN (985)
INNER JOIN
ItemGroup e ON b.ItemGroupId = e.ItemGroupId
LEFT JOIN
ComboMaster c ON a.ComboId = c.ComboId
LEFT JOIN
ComboGroup d ON a.ComboGroupId = d.GroupId
【问题讨论】:
【参考方案1】:我想你只需要一个partition by
:
( a.ComboAmount + sum(a.TotalPrice) over (partition by combouniqueid order by a.OrderDetailId) ) as new_comboamount
【讨论】:
以上是关于如何从唯一 id 基础 varchar 数据类型中获取值的主要内容,如果未能解决你的问题,请参考以下文章
数据库SQL语句中如何将float类型存入的SQL语句 例如 字段 id int,name varchar,number float