[英]SQL create new column based on a less than operand of another column
I would like to create a new column based on the amount of an existing column.我想根据现有列的数量创建一个新列。 I am getting an error with my code below and I understand it is because <=, >= type operands can only return one record.
我在下面的代码中遇到错误,我明白这是因为 <=, >= 类型操作数只能返回一条记录。 I believe I should be using an IN or ANY, ALL possibly operand but cannot seem to implement it properly.
我相信我应该使用 IN 或 ANY,所有可能的操作数,但似乎无法正确实现它。
ALTER TABLE SALES_TOTAL ADD REFUNDS INTEGER(20);
UPDATE SALES_TOTAL SET REFUND = SELECT [SALE_TOTAL] from [SALES_TOTAL] WHERE[SALES_TOTAL] < 10
Could anyone provide an example of how to do so?谁能提供一个如何做到这一点的例子?
Thanks in advance.提前致谢。
That's what you probably want:这就是你可能想要的:
alter table SALES_TOTAL add REFUNDS int unsigned not null default 0;
update SALES_TOTAL set REFUNDS = SALE_TOTAL where SALE_TOTAL < 10;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.