add batch
remove batch
split batch
comment selection
show hidden batches
hide batch
highlight batch
db<>fiddle
Db2
Firebird
MariaDB
MySQL
Node.js
Oracle
Postgres
SQL Server
SQLite
TimescaleDB
YugabyteDB
Developer-C 11.1
3.0
4.0
10.2
10.3
10.4
10.5
10.6
10.7
10.8
10.9
5.5
5.6
5.7
8.0
18
11g Release 2
18c
21c
23c
8.4
9.3
9.4
9.5
9.6
10
11
12
13
14
15
16
2012
2014
2016
2017
2017 (Linux)
2019
2019 (Linux)
2022
3.8
3.16
3.27
3.39
2.11
2.14
2.6
2.8
2.18
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
Sakila
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
AdventureWorks
no sample DB
no sample DB
AdventureWorks
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
run
markdown
donate
feedback
about
By using db<>fiddle, you agree to license everything you submit by
Creative Commons CC0
.
CREATE TABLE 門市安全量基本檔 ([商品貨號] int, [安全量] int,門市編號 varchar(20)) ; CREATE TABLE 商品基本檔 ([商品貨號] int,基本撥量 int, [大類編號] int,淘汰 varchar(20) ) ; INSERT INTO 門市安全量基本檔 ([商品貨號], [安全量],[門市編號]) VALUES (11092, 48,'1001'), (1103, 36,'1001'), (15584, 16,'1001') ; INSERT INTO 商品基本檔 ([商品貨號],基本撥量, [大類編號],淘汰) VALUES (11092,4, 1,'1'), (1103,3, 1,'1'), (15584,3, 1,'1') ; select * into #temp_table from ( SELECT a.商品貨號 取代商品貨號,a.安全量,b.基本撥量 , case when (a.安全量/2) % b.基本撥量 = 0 then a.安全量/2 else b.基本撥量 * ((a.安全量/2)/b.基本撥量+1) end [新安全量] FROM 門市安全量基本檔 AS a RIGHT JOIN 商品基本檔 AS b ON b.商品貨號=a.商品貨號 WHERE (b.大類編號 BETWEEN '1' AND '7') AND a.門市編號='1001' AND b.淘汰='1' ) T update 門市安全量基本檔 set 安全量 = (select [新安全量] from #temp_table where 商品貨號 = 取代商品貨號) where 商品貨號 in (select 取代商品貨號 from #temp_table ); select * from 門市安全量基本檔;
商品貨號
安全量
門市編號
11092
24
1001
1103
18
1001
15584
9
1001