MySQL查询更新和SQLite问题

时间:2019-04-09 20:55:53

标签: javascript mysql

我的桌子是:

id |    les_mo_id      |    les_comp     |    les_ch_comp
.1.|...................|........0....... |...................
.2.|........1..........|.................|.........1.........
.3.|........1..........|.................|.........1.........
.4.|...................|........0....... |...................
.5.|........4..........|.................|.........2.........
.6.|........4..........|.................|.........1.........
.7.|...................|........0........|...................
.8.|........7..........|.................|.........1.........
.9.|........7..........|.................|.........4.........

我必须运行查询,但是我不知道如何设置它。我只是在学习这种语言。

我需要更新列'les_comp',添加ID为les_mo_id = 1的列'les_ch_comp'的所有值

这是我的查询

UPDATE base_app SET les_comp = (SELECT SUM(les_ch_comp) WHERE les_mo_id = "1") WHERE id = "1";

2 个答案:

答案 0 :(得分:0)

就像UUeerdo的姿势一样:

更新base_app SET les_comp =(SELECT SUM(les_ch_comp) FROM base_app WHERE les_mo_id =“ 1”)WHERE id =“ 1”

答案 1 :(得分:0)

您的查询中应该有FROM。试试:

UPDATE base_app SET lesson_complete = (SELECT SUM(lesson_child_complete) FROM 
base_app WHERE lesson_mother_id = "1") WHERE id = "1"