2012-03-15 106 views
0

我是PostgreSQL的新手。如何创建一个下拉列表?

我在想,如何制作一个列下拉列表。

所以我有一张名为学生的表。在那里有一个名为“student_type”的专栏,这意味着学生是兼职学生,全日制学生还是三明治课程的学生。

所以我想让“student_type”有一个下拉列表,有3个选择:“兼职”学生,“全职”和“三明治”。

我该怎么做?

(我使用pgAdmin的创建DATABSE,顺便说一句。)

+0

DropDown没有在数据库中指定的东西。您必须在访问数据库的前端执行此操作。 – 2012-03-15 21:14:46

+0

@a_horse_with_no_name,好吧,我使用JSP和Servlet作为前端。我如何写我的“student_type”列作为下拉列表使用? – 2012-03-15 21:27:33

回答

1

下拉是一种客户端的事情,应该相应处理。但据一个关系数据库参与应该存在与idtype列student_type关系,你会质疑这样的:

select st.id, st.type 
from student_type st 
inner join student s on s.type_id = st.id 
group by st.id, st.type 
order by st.type 

内连接是确保你不显示的选项在学生表中不存在,因此如果选择,将产生空的结果。在客户端,id应该是选项的值,并且输入选项文本。

如果没有student_type关系作为不良数据库设计的结果,或者如果你只允许查询非规范化的视图,你仍然可以使用学生关系:

select distinct student_type 
from student 
order by student_type 

在这种情况下,student_type会既是期权价值又是期权文本。

+0

非常感谢Clodoaldo,这对我有所帮助。 – 2012-03-18 18:18:54