处理泛型选择语句 [英] Handling a generic select statement
问题描述
亲爱的专家
需要一份可以执行此操作的通用声明
MASTER
-------
IDNO NAME GENDER EDUCATION
--- -----------------------------------
001 JAMES MALE HIGH SCHOOL
002 JOHN MALE UNIVERSITY
003 AMY女子高中
004 PAT女子大学
005 ANN女子高中
性别可以是'全部/男性/女性'
教育可以是'全部/高中/大学'
需要一般用途选择语句如下< br $>
选择*来自MASTER WHERE GENDER =''AND EDUCATION =''
你如何处理一个generIc Select语句来处理
'ALL'除了'MALE / FEMALE'之外的GENDER
'ALL'用于教育到'高中/大学'
请协助
我的尝试:
这就是我的尝试。请assit
Dear Expert
Need a universal statement which can perform this
MASTER
-------
IDNO NAME GENDER EDUCATION
--------------------------------------
001 JAMES MALE HIGH SCHOOL
002 JOHN MALE UNIVERSITY
003 AMY FEMALE HIGH SCHOOL
004 PAT FEMALE UNIVERSITY
005 ANN FEMALE HIGH SCHOOL
GENDER can be 'ALL/MALE/FEMALE'
EDUCATION can be 'ALL/HIGH SCHOOL/UNIVERSITY'
Need a general purpose Select statement as follows
Select * from MASTER WHERE GENDER='' AND EDUCATION=''
How do you handle a generIc Select statement to handle
'ALL' for GENDER in addition to 'MALE/FEMALE'
'ALL' for EDUCATION in addition to 'HIGH SCHOOL/UNIVERSITY'
Please assist
What I have tried:
This is what I have tried . please assit
推荐答案
对于你想要任何一个的通用语句,只需将它从WHERE子句中排除:
For generic statements where you want "any of them", just exclude it from the WHERE clause:
SELECT * FROM Master WHERE Education='UNIVERSITY'
将返回任何性别。同样,
Will return any gender. Similarly,
SELECT * FROM Master WHERE Gender='MALE'
将返回任何教育状态。
但这是一个非常糟糕的数据库设计:存在大量重复。您应该考虑设置单独的性别和教育表格:
性别
Will return any education status.
But that's a very poor DB design: there is a huge amount of duplication. You shoudlk consider setting up separate Gender and Education tables:
Gender
Id INT, IDENTITY, PRIMARY KEY
Desc NVARCHAR
教育
Education
Id INT, IDENTITY, PRIMARY KEY
Desc NVARCHAR
然后,您可以对主表中的每个ID字段使用外键,而不是多次存储描述,并根据需要使用JOIN来组合表格以进行输出。
You then use a foreign key to each ID field in your main table instead of storing the description so many times, and use JOINs to "combine" the tabels for output as necessary.
这篇关于处理泛型选择语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!