我有一个包含调查数据的表,两个数据点是 Ethnicity 和 Flavor_Pref。Flavor_Pref 保存一个整数 1、2、3、4、5。1 = 非常不喜欢,5 非常喜欢。
Ethnicity Flavor_Pref
African American 3
Caucasian 2
Asian 4
Hispanic 1
African American 3
Caucasian 4
Asian 5
Hispanic 2
African American 4
Caucasian 1
Asian 4
Hispanic 2
African American 3
Caucasian 2
Asian 2
Hispanic 1
我想运行一个查询来获得 4 列,每个民族一个。每个组有不同数量的响应。
这就是我正在做的事情:我得到了超过 100 万个结果……我只有 400 个调查。
select AA.Flavor_Pref as AA,H.Flavor_Pref as H,C.Flavor_Pref AS C,
A.Flavor_Pref AS A from
(SELECT ETHNICITY,Flavor_Pref FROM FLAVORS WHERE ETHNICITY = 'AFRICAN AMERICAN')AS AA
CROSS JOIN
(SELECT ETHNICITY,Flavor_Pref FROM FLAVORS WHERE ETHNICITY = 'HISPANIC') AS H
CROSS JOIN
(SELECT ETHNICITY,Flavor_Pref FROM FLAVORS WHERE ETHNICITY = 'CAUCASIAN') AS C
CROSS JOIN
(SELECT ETHNICITY,Flavor_Pref FROM FLAVORS WHERE ETHNICITY = 'ASIAN' ) AS A
我正在寻找的是:在这种情况下,西班牙裔结果较少,因此没有报告任何内容。
African Americans Hispanic Caucasian Asian
3 1 2 4
3 2 4 5
4 2 1 5
. . . .
. . . .
. . . .
3 2 4
2 1 1