从多列中选择查询 [英] Select Query from multiple column

查看:63
本文介绍了从多列中选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在使用sql server 2005
我有一个带有10列的表格,其中5个为"companyName",5个为"HRstatus".
我希望如果我选择一家公司和一个HRStatus,则所有具有匹配记录的数据都应该出现. 我已经完成了用单个Hrstatus进行修整的代码,我该如何为两者做这件事.

Currently I am working on sql server 2005
i am having a single table with 10 column in which 5 are of "companyName" and 5 for their "HRstatus".
I want that if i select a company and a HRStatus all data with matching records should come..
i have done the code for retreiving with single Hrstatus how can i do it for both..

select *
from TotTab
where 'Dispatch' in (HRStatus,HRStatus2,HRStatus3,HRStatus4,HRStatus1)
   or 'Rejected' in (HRStatus,HRStatus2,HRStatus3,HRStatus4,HRStatus1)




我希望查询将与"hrStatus"匹配的"companyName"

any1 plz建议


在此先感谢
Vikram Acharya




i want the query that will match the "companyName" with "hrstatus"

any1 plz suggest


thanks in advance
Vikram Acharya

推荐答案

如果可能,应该更改数据库的设计.不要将重复数据存储在不同的列中,而应将它们存储在不同的行中.因此,对表进行组织,以便在单个列中包含公司名称,在另一列中包含hrstatus.可能的话,如果需要的话,您可以有其他列来对行进行分类(例如,如果订购了公司名称或状态,则为orderno).

加法,归一化:
规范化表格的正确方法取决于几个因素,但从以下几个方面入手,您可以考虑以下内容:
If possible, you should change the design of the database. Do not store repeating data in different columns, store them on different rows. So organize the tables so that you have the company name in a single column and hrstatus in another column. Possibly if you need you can have other columns to categorize the rows (for example orderno if the company names or statuses are ordered etc).

Addition, normalization:
The correct way to normalize your table depends on several factors but to get something to start with, could you consider something like:
Employee
- Srno as primary Key
- Cid (for identification of employee)
- Date,
- Name,
- ContactNumber,
- DOB,
- Age,
- Location,
- Qualification,

EmployeeHRStatus
- Srno (foreign key to Employee)
- HRStatus,
- StatusDate

EmployeeSentTo
- Srno (foreign key to Employee)
- SentTo,
- SentToDate

etc.


select *
from TotTab
where ('your_status_condition' = HRStatus1 AND 'your_company_name' = Companyname1) OR ('your_status_condition' = HRStatus2 AND 'your_company_name' = Companyname2) OR ('your_status_condition' = HRStatus3 AND 'your_company_name' = Companyname3)OR ('your_status_condition' = HRStatus4 AND 'your_company_name' = Companyname4)
OR ('your_status_condition' = HRStatus5 AND 'your_company_name2' = Companyname5)   


我不确定我是否理解您的问题对,我只是一个初学者,但我想尝试提供帮助


I''m not sure if i understood your question right and i''m just a beginner but i wanted to try to help


这篇关于从多列中选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆