我正在用 oracle 编写 sql 查询。我的要求是我想用大小写有条件地更新数据库列。下面是我在三个表中使用的示例数据。
create table z_product(uuid int, variationvalue varchar(10));
create table z_listprice(productid int, price int);
create table z_variation(masterproductid int, productid int);
insert into z_product values(1,null);
insert into z_product values(2,null);
insert into z_product values(3,null);
insert into z_product values(4,null);
insert into z_product values(5,null);
insert into z_product values(6,null);
insert into z_listprice values(1,10);
insert into z_listprice values(3,20);
insert into z_listprice values(5,10);
insert into z_listprice values(6,19);
insert into z_variation values(2, 1);
insert into z_variation values(2, 3);
insert into z_variation values(4, 5);
insert into z_variation values(4, 6);
如果“masterproductid”和“eqaul”的所有价格值都相等,如果价格与“notequal”消息不同,我想更新“variationvalue”列。
我试过的查询是
UPDATE z_product pr SET pr.variationvalue =
CASE WHEN ( SELECT numberofrows FROM (SELECT COUNT(*) AS numberofrows, pricecount , productmasterid
FROM ( SELECT COUNT(prl.price) AS pricecount , prl.price AS price, prv.masterproductid AS productmasterid
FROM z_variation prv, z_listprice prl
WHERE prv.masterproductid = (SELECT prv.masterproductid
FROM z_variation prv
WHERE prv.productid = prl.productid GROUP BY prv.masterproductid)
AND prl.productid = prv.productid
GROUP BY prl.price, prv.masterproductid)
GROUP BY pricecount , productmasterid)) = '1'
AND
( SELECT pricecount FROM (SELECT COUNT(*) AS numberofrows, pricecount , productmasterid
FROM ( SELECT COUNT(prl.price) AS pricecount , prl.price AS price, prv.masterproductid AS productmasterid
FROM z_variation prv, z_listprice prl
WHERE prv.masterproductid = (SELECT prv.masterproductid
FROM z_variation prv
WHERE prv.productid = prl.productid GROUP BY prv.masterproductid)
AND prl.productid = prv.productid
GROUP BY prl.price, prv.masterproductid)
GROUP BY pricecount , productmasterid)) >1
THEN 'equal'
ELSE 'notequal' END
WHERE pr.uuid = (SELECT prv.masterproductid
FROM z_variation prv, z_listprice prl
WHERE prv.productid = prl.productid
AND pr.uuid = prv.masterproductid GROUP BY prv.masterproductid)
这个查询有什么问题。我在哪里做错了。任何建议将不胜感激