Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.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_Oracle - Fatal编程技术网

Sql 从其他表更新表查询

Sql 从其他表更新表查询,sql,oracle,Sql,Oracle,我有以下问题: 在我的数据库中,我有第一个表:item_price Id_item Dept Price 1 7 1500 2 7 100 3 7 200 4 7 300 5 7 400 6 7 0 7 7 0 8 7 0 9 7

我有以下问题:

在我的数据库中,我有第一个表:item_price

Id_item   Dept   Price
1          7      1500
2          7      100
3          7      200
4          7      300
5          7      400
6          7       0
7          7       0
8          7       0
9          7       0
10         7       0
我有第二张桌子:订单历史

Order_no    Id_item   Dept    Price    Date_order
A1             1       2       700     01/05/2014
A2             2       3       800     02/21/2014
A3             3       7       200     03/25/2013
A4             3       7       300     04/15/2014
A5             4       7       300     05/05/2014
A6             5       7       400      06/15/2014
A7             6       7        120    07/16/2014
A8             7       7       1400     08/19/2014
A9             8       7       150      09/25/2014
A10            9       7       4500    10/31/2014
A11           10       7       8000    11/15/2014
我现在想做的就是: 我想更新item_price中的字段price,其中item_price中的Id_item=订单历史记录中的Id_item 物料中的部门\价格=订单中的部门\历史记录和 订单日期=2014年5月1日至2014年7月11日

类似===

update item_price 
set price = (select item_number from item_history )
where date_order = '01/01/2014' - '11/07/2014' and dept = '7'; 

你们能帮帮我吗?

Oracle确实提供了对连接更新的支持。您可以这样做(注意,我没有测试过):

MySQL语法如下:

UPDATE item_price ip
    JOIN Order_history oh ON oh.id_item = ip.id_item  
    WHERE
    oh.date_order between 
        STR_TO_DATE('01/01/2014', '%m/%d/%Y') and 
        STR_TO_DATE('11/07/2014', '%m/%d/%Y') 
SET ip.price = oh.price;
SQL 首先对开发人员进行测试并验证结果!请

UPDATE item 
SET item.Price = history.price 
FROM dbo.item_price item 
JOIN dbo.Order_History history ON item.Id_Item= history.Id_Item AND item.Dept = History.Dept 
WHERE history.Date_Order Between '01/05/2014' AND '11/07/2014'

如果我在mysql上测试它呢?现在我在mysqlumh上模拟,您已经将您的问题标记为oracle。MySql语法更简单,我使用的是xampp localhost/phpmyadmin。它给了我一个错误:#1064-您的SQL语法有一个错误;检查与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在第3行使用“FROM dbo.item\u price item JOIN dbo.Order\u History ON item.Id\u item=histori”这对Oracle和MySQL都无效
UPDATE item 
SET item.Price = history.price 
FROM dbo.item_price item 
JOIN dbo.Order_History history ON item.Id_Item= history.Id_Item AND item.Dept = History.Dept 
WHERE history.Date_Order Between '01/05/2014' AND '11/07/2014'