Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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 - Fatal编程技术网

Sql 如何添加两列以创建新列

Sql 如何添加两列以创建新列,sql,Sql,折扣挂载在第3行中显示为无效列名。我该怎么做才能使其成为产品表的一部分 编辑:还有,我如何使折扣百分比计算为百分比?您可以在任何地方使用折扣装载,或者您可以使用 这将是在SQL Server中执行此操作的脚本。如果您遵循上面的链接,您将看到如何在ManagementStudio中执行此操作 SELECT ProductName, ListPrice, Discountpercent from Products SELECT (ListPrice/nullif(Discountpercent,

折扣挂载在第3行中显示为无效列名。我该怎么做才能使其成为产品表的一部分


编辑:还有,我如何使折扣百分比计算为百分比?

您可以在任何地方使用折扣装载,或者您可以使用

这将是在SQL Server中执行此操作的脚本。如果您遵循上面的链接,您将看到如何在ManagementStudio中执行此操作

SELECT  ProductName, ListPrice, Discountpercent from Products
SELECT  (ListPrice/nullif(Discountpercent, 0)) as DiscountAmount FROM Products
SELECT  (ListPrice + DiscountAmount) as DiscountPrice  FROM Products;

您可以将
(ListPrice/nullif(Discountpercent,0))
写在任何您想使用DiscountAmount的地方,也可以使用

这将是在SQL Server中执行此操作的脚本。如果您遵循上面的链接,您将看到如何在ManagementStudio中执行此操作

SELECT  ProductName, ListPrice, Discountpercent from Products
SELECT  (ListPrice/nullif(Discountpercent, 0)) as DiscountAmount FROM Products
SELECT  (ListPrice + DiscountAmount) as DiscountPrice  FROM Products;

您可以使用子查询或CTE:

ALTER TABLE dbo.Products ADD DiscountAmount AS  (ListPrice/nullif(Discountpercent, 0))

或者,重复
DiscountAmount

定义中的表达式。您可以使用子查询或CTE:

ALTER TABLE dbo.Products ADD DiscountAmount AS  (ListPrice/nullif(Discountpercent, 0))

或者,重复
DiscountAmount

定义中的表达式,您实际使用的是哪个数据库?我删除了无关的数据库标记。请随意为您真正使用的数据库添加标记。您实际使用的是哪个数据库?我删除了无关的数据库标记。请随意为您真正使用的数据库添加标记。