Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示SQL算法的结果_Sql_Math - Fatal编程技术网

显示SQL算法的结果

显示SQL算法的结果,sql,math,Sql,Math,我对SQL相当陌生。我有一个表,有几列:商品ID、购买价格和售出价格。我需要编写一个sql语句来返回购买价格和售出价格之间的差额以及商品ID 谢谢 Select itemID, purchasePrice - soldPrice from myTable; 这将返回所有ItemID,以及每个ItemID的价格差异。您可以向筛选器添加where子句。以下是一个示例: declare @itemID varchar(55), @purchasePrice float, @salePrice flo

我对SQL相当陌生。我有一个表,有几列:商品ID、购买价格和售出价格。我需要编写一个sql语句来返回购买价格和售出价格之间的差额以及商品ID

谢谢

Select itemID, purchasePrice - soldPrice
from myTable;

这将返回所有ItemID,以及每个ItemID的价格差异。您可以向筛选器添加where子句。

以下是一个示例:

declare @itemID varchar(55), @purchasePrice float, @salePrice float

    set @itemID = 'Shirt'
    set @purchasePrice = 65.50
    set @salePrice = 78.98

    select @itemID, @salePrice - @purchasePrice

选择[price Seld]-[purchase price]作为与…[购买价格]的差异。
在这里,您可以找到类似这样的简单问题的答案假设您出售的价格高于购买的价格,这将导致一个负数。