0
我有一個交叉表查詢與幾個感興趣的屬性。在這個查詢中,特定屬性的存在是或不是(1 =是0 =否)。現在,如果一個人有兩個屬性,那麼他們在數據集中由兩行表示。如果他們有三個問題,那麼他們由三行代表。我需要一種方法來使多個屬性顯示在同一行上。例如,如果他們患有糖尿病和菸草,那麼在該列下一行將具有「1」,而不是現在,在糖尿病和糖尿病全部爲0之後。而「菸草」行在每列中除了菸草(它是一個菸草)之外都有一個0。如何將交叉表查詢合併到一行中? Access 2007
是的輸出看起來像一個屏幕帽。我只需要每位患者一行,而不管他們有多少問題。
下面是我的sql。
TRANSFORM IIf([tblComorbidity.comorbidityexplanation]=[tblComorbidity.comorbidityexplanation],1,0) AS Morbidity
SELECT
Person.PersonID,
Person.Age,
tblKentuckyCounties.Metro,
tblKentuckyCounties.Appalachian,
Person.asiaAdmit,
Person.Sex
FROM tblKentuckyCounties
INNER JOIN (tblComorbidity
INNER JOIN (Person
INNER JOIN tblComorbidityPerson ON Person.PersonID = tblComorbidityPerson.personID
) ON tblComorbidity.ID = tblComorbidityPerson.comorbidityFK
) ON tblKentuckyCounties.ID = Person.County
WHERE (((tblComorbidity.comorbidityexplanation)="anxiety and depression"
Or (tblComorbidity.comorbidityexplanation)="heart"
Or (tblComorbidity.comorbidityexplanation)="respiratory"
Or (tblComorbidity.comorbidityexplanation)="uti"
Or (tblComorbidity.comorbidityexplanation)="diabetes"
Or (tblComorbidity.comorbidityexplanation)="hypertension"
Or (tblComorbidity.comorbidityexplanation)="tobacco"))
GROUP BY
Person.PersonID,
Person.Age,
tblKentuckyCounties.Metro,
tblKentuckyCounties.Appalachian,
Person.asiaAdmit,
Person.Sex,
tblKentuckyCounties.Appalachian,
tblKentuckyCounties.Metro,
tblComorbidity.comorbidityexplanation
PIVOT tblComorbidity.comorbidityexplanation;
我相信這是關於真棒:)。 – dzilla