データベース内のすべての回答者の郵便番号と州の両方を見つける2つのクエリがあります。はい、どうぞ
郵便番号の場合:
select top 100 S.ID as SurveyID, S.SID, S.SurveyNumber, S.ABCSurveyName, SE.RespondentID, Q.name as QuestionName, rp.Condition as ZipCode
from Surveys S
join Sessions SE
on S.id = SE.SurveyID
join RespondentProfiles rp
on RP.RespondentID = SE.RespondentID
join Questions Q
on Q.ID = rp.QuestionID
where q.name = 'ZIP'
and S.ID = 13900
and Q.LK_RecordStatusID = 1
状態の場合:
select VW.ID as SurveyID, VW.SID, SurveyNumber, ABCSurveyName, RespondentID, VW.Name as QuestionName, st.Code as State
from (
select top 100 S.ID, S.SID, S.SurveyNumber, S.ABCSurveyName, SE.RespondentID, Q.name, rp.Condition
from Surveys S
join Sessions SE
on S.id = SE.SurveyID
join RespondentProfiles rp
on RP.RespondentID = SE.RespondentID
join Questions Q
on Q.ID = rp.QuestionID
where S.ID = 13900
and q.name = 'STATE'
and Q.LK_RecordStatusID = 1
) VW
join LK_States st
on st.ID = vw.Condition
これは機能しますが、すべてを1つのテーブル、つまり郵便番号と州にまとめたいと思います。
ありがとう!
質問スキーマ:
Column_nameタイプ計算された長さPrecScaleNullable
TrimTrailingBlanks FixedLenNullInSource Collation
ID int no 4 10 0 no (n/a) (n/a) NULL
SID nvarchar no 128 yes (n/a) (n/a) SQL_Latin1_General_CP1_CI_AS
Name nvarchar no 64 yes (n/a) (n/a) SQL_Latin1_General_CP1_CI_AS
QuestionIdentifier nvarchar no 128 yes (n/a) (n/a) SQL_Latin1_General_CP1_CI_AS
ParentID int no 4 10 0 yes (n/a) (n/a) NULL
LK_QuestionTypeID int no 4 10 0 yes (n/a) (n/a) NULL
LK_QuestionCategoryID int no 4 10 0 yes (n/a) (n/a) NULL
LK_IndustryID int no 4 10 0 yes (n/a) (n/a) NULL
OptionMask nvarchar no 512 yes (n/a) (n/a) SQL_Latin1_General_CP1_CI_AS
MetaTags ntext no 16 yes (n/a) (n/a) SQL_Latin1_General_CP1_CI_AS
Order int no 4 10 0 yes (n/a) (n/a) NULL
Rows int no 4 10 0 yes (n/a) (n/a) NULL
Columns int no 4 10 0 yes (n/a) (n/a) NULL
IsDisplay bit no 1 yes (n/a) (n/a) NULL
AnswerLifespan int no 4 10 0 yes (n/a) (n/a) NULL
CreateUserID int no 4 10 0 yes (n/a) (n/a) NULL
CreateDate datetime no 8 yes (n/a) (n/a) NULL
UpdateUserID int no 4 10 0 yes (n/a) (n/a) NULL
UpdateDate datetime no 8 yes (n/a) (n/a) NULL
LK_RecordStatusID bit no 1 yes (n/a) (n/a) NULL
LK_QuestionClassID int no 4 10 0 yes (n/a) (n/a) NULL
LK_QuestionVisibilityID int no 4 10 0 yes (n/a) (n/a) NULL
DisplayLK_QuestionTypeID int no 4 10 0 yes (n/a) (n/a) NULL