gpt4 book ai didi

android - SQLite 查询没有按预期工作

转载 作者:行者123 更新时间:2023-11-29 21:04:47 26 4
gpt4 key购买 nike

我对 SQLite 查询有疑问,无法解决。这些是我的 table :

CREATE TABLE Exercise 
(
e_id int auto_increment primary key,
name varchar(20)
);

CREATE TABLE PersonalList
(
p_id int auto_increment primary key,
name varchar(20)
);

CREATE TABLE Exercise_Personal_List
(
e_id_m int auto_increment primary key,
p_id_m int
);


INSERT INTO Exercise
(e_id, name)
VALUES
('1', 'exercise1'),
('2', 'exercise2'),
('3', 'exercise3'),
('4', 'exercise4'),
('5', 'exercise5'),
('6', 'exercise6');

INSERT INTO PersonalList
(p_id, name)
VALUES
('1', 'list1'),
('2', 'list2'),
('3', 'list3');

INSERT INTO Exercise_Personal_List
(e_id_m, p_id_m)
VALUES
('2', '1'),
('4', '1'),
('6', '1'),
('1', '2');
  • 练习表:一组练习
  • PersonalList表:列表的集合
  • Exercise_Personal_List:对哪个 Exercise 是哪个 Exercise_Personal_List 的一部分的引用

我正在尝试获取尚未添加到特定列表的练习列表。例如。未添加到列表 1 中的那些。我的查询:

select * from Exercise 
where e_id not in (
select e_id from Exercise_Personal_List
where p_id_m like '1'
)

结果为空。我没有在查询中看到错误。正确的结果应该是 1, 3, 5。

顺便说一句,我正在使用 http://sqlfiddle.com来评价这个东西。测试速度更快:)

感谢您的帮助!

最佳答案

我认为您的意思是执行以下查询,其中 e_id 的第二个实例已更改为 e_id_m:

select * from Exercise 
where e_id not in (
select e_id_m from Exercise_Personal_List
where p_id_m like '1'
)

关于android - SQLite 查询没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24918326/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com