2 回答

TA貢獻1966條經驗 獲得超4個贊
相關的更新就可以了。例如:
update pack_of_light p, Komplektacija k
set p.Quantity = k.Quantity
where k.Serial = p.Serial and k.Item = p.Item
結果:
Device Item Serial Quantity
-------- ------ ------- --------
device1 Item1 12345 1
device2 Item4 2141 0
device3 Item6 23241 0
您可以在DB Fiddle中查看正在運行的示例。

TA貢獻1856條經驗 獲得超11個贊
我已經設法從兩個表中獲取匹配的數據。自從我提到 PHP 以來,我不確定是否可以在這個論壇上詢問更多詳細信息,但是我決定使用 python 來運行腳本:
def compare_2_tables(conn):
cur = conn.cursor()
query = "UPDATE pack_to_light p, komplektacija k SET p.Quantity = k.Quantity WHERE k.Serial = p.Serial and k.Item = p.Item"
cur.execute(query)
myConnection.commit()
for p.Device,p.Quantity in cur.fetchall() :
print (Device, Quantity)
string = Device+"/"+Quantity;
print (string)
mqttc.publish(string,quantity)
我在這里想做的是提取有關更新了哪個設備以及數量的信息。在前面的示例中,我需要返回 device1 和 1。我需要這兩個變量才能向 device1 發送正確的消息。有沒有懂 python 知識的人可以指導我完成這個任務?
- 2 回答
- 0 關注
- 126 瀏覽
添加回答
舉報