您好我是SQL数据库的新手。
我有两个表,一个是“Master”,另一个是“Sub”,就像这个
Master
uid(primary key) f_name l_name
1 fAaa lAaa
2 fBbb lBbb
第二张表
Sub
tid(primary key) uid(foreign key) time is_free
1 1 1:00AM 0
2 1 2:00AM 1
3 1 3:00AM 0
4 2 1:30PM 0
5 2 2:30PM 1
从两个表中我们可以说用户fAaa lAaa在凌晨2:00是免费的,而不是在凌晨1:00和凌晨3:00免费。
现在我想像这样更新,对于用户1(fAaa lAaa),我想删除时间凌晨2:00,并且想要为用户1插入新的两次,比如应该是我的用户1的5:00 AM和6:00加入查询以进行更新。
请帮帮我! 感谢
答案 0 :(得分:1)
喜欢这个吗?
DELETE FROM secondtable WHERE uid = 1 AND (time = "1:00AM" OR time = "2:00AM");
INSERT INTO secondtable (uid, time) VALUES (1, "5:00AM"), (1, "6:00AM");
或者
UPDATE secondtable SET time = "5:00AM" WHERE uid = 1 AND time = "1:00AM";
UPDATE secondtable SET time = "6:00AM" WHERE uid = 1 AND time = "2:00AM";
这是一些非常基本的东西,我建议你搜索“sql delete from”,“sql insert into”,“sql update”,并寻找初学者教程。