我已经准备好像这样的SQL查询
UPDATE Towar
JOIN TowarZamowienie ON Towar.Tow_id = TowarZamowienie.Tow_id
SET Tow_ilosc = Tow_ilosc - CAST(TowZam_ilosc AS UNSIGNED);
它返回我修改记录:0。我承认我在数据库中有记录
以下是我的表格:
TowarZamowienie
1 TowZam_id int(19) AUTO_INCREMENT
2 Tow_id int(255)
3 Zam_id int(255)
4 TowZam_ilosc varchar(10)
Towar
1 Tow_id int(255)
2 Tow_ilosc int(6)
答案 0 :(得分:1)
答案 1 :(得分:0)
试试此代码
UPDATE Towar
JOIN
TowarZamowienie ON Towar.Tow_id = TowarZamowienie.TowZam_id
SET
Tow_ilosc = Tow_ilosc - CAST(TowZam_ilosc AS UNSIGNED);
答案 2 :(得分:0)
为什么不将整数“转换”为Varchar?如果Varchar真的有10个字符而Integer只需要6个数字怎么办?试试这个:
CAST(Tow_ilosc as CHAR(10))
或
CONVERT(Tow_ilosc, CHAR(10))
或只在where子句中使用like
WHERE Tow_ilosc LIKE TowZam_ilosc
(我不喜欢)^^
答案 3 :(得分:0)
UPDATE Towar, TowarZamowienie
SET Towar.Tow_ilosc = Towar.Tow_ilosc - CAST(TowarZamowienie.TowZam_ilosc AS UNSIGNED)
WHERE Towar.Tow_id = TowarZamowienie.TowZam_id;
- OR
UPDATE Towar
JOIN TowarZamowienie ON Towar.Tow_id = TowarZamowienie.TowZam_id
SET Tow_ilosc = Tow_ilosc - CAST(TowZam_ilosc AS UNSIGNED);