如何从关系数据库中的多值属性中检索数据?
以下是我的数据库,有 4 个表(学生、课程、模块、讲师)。我想知道这个数据库是否正确,如果我做得正确,我如何使用学生 ID 从表中检索数据,如下所示。
- 模块有哪些 学生10122342 有? >>预期答案:cn103、cn201
(pk) = primary key and (fk)=foreign key
接下来我想将上面的表中的一些值导入到新创建的表中?情况是我想从上面的表中导入名为“Everyone”的新创建表的“id”属性中的“s_id”和“i_id”;同时我还想为“Everyone”表的“type”属性生成“0”/“1”值,其中从“s_id”导入的 id 值为 0,从“s_id”导入的其余 id 值为 1 i_id'。以下是我预期的新数据库表。
Everyone
id |type |
-----------------
10122345 | 0 |
10122342 | 0 |
10222346 | 0 |
20432343 | 1 |
20432311 | 1 |
20532334 | 1 |
请问有人可以帮助我吗?可以用mysql和php来做吗?谢谢。
Following is my database with 4 tables(Student, Course, Module, Instructor). And I wan to know whether this database is correct or not and if I am doing right how can I retrieve data from tables using student id as below.
- What are the modules student 10122342
has?
>>Expected answer: cn103, cn201
(pk) = primary key and (fk)=foreign key
The next thing is I wan to import some values from those above tables to a newly created table? the situation is I wan to import 's_id' and 'i_id' from above tables in 'id' attribute of newly crated table named "Everyone"; at the same time I also want to generate '0'/'1' value for 'type' attribute of "Everyone" table where 0 value for those id which are imported from 's_id' and 1 for rest of the ids imported from 'i_id'. Following is my expected new database table.
Everyone
id |type |
-----------------
10122345 | 0 |
10122342 | 0 |
10222346 | 0 |
20432343 | 1 |
20432311 | 1 |
20532334 | 1 |
Please Can anyone help me? is it possible to do with mysql and php? THanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该是你的第一个问题的答案:
我无法给出你的第二个问题的答案,尽管它应该是带有连接的东西,这可能会有所帮助:MySQL 插入&加入
This should be the answer to your first question:
I can't come up with the answer to your second question, though it should be something with joins, this might help: MySQL Insert & Joins