有没有办法加入下面的SELECT语句?
Is there a way to join the following SELECT statements?
SELECT
date,
people_fully_vaccinated AS 'Australia'
FROM vaccinations
WHERE location = 'Australia';
SELECT
date,
people_fully_vaccinated AS 'United States'
FROM vaccinations
WHERE location = 'United States';
SELECT
date,
people_fully_vaccinated AS 'France'
FROM vaccinations
WHERE location = 'France';
SELECT
date,
people_fully_vaccinated AS 'Israel'
FROM vaccinations
WHERE location = 'Israel';
您已经将位置作为国家/地区名称。所以不需要 select 列 people_fully_vaccinated
如果您想按特定国家/地区进行过滤,请使用以下内容:
SELECT date
,location
FROM vaccinations
WHERE location = 'Australia'
OR location = 'United States'
OR location = 'France'
OR location = 'Israel'
如果你想得到全部,那么使用下面这个:
SELECT date,location FROM vaccinations;
如果您不关心每个国家/地区的数据是否在不同的行中,您可以使用:
select date,
location,
people_fully_vaccinated
from vaccinations
where location in ('Australia','United States','France','Israel');
如果您希望每个国家/地区的数字在每个日期出现在同一行,您可以使用:
select date,
sum(case when location = 'Australia' then people_fully_vaccinated else 0 end) as "Australia",
sum(case when location = 'United States' then people_fully_vaccinated else 0 end) as "United States",
sum(case when location = 'France' then people_fully_vaccinated else 0 end) as "France",
sum(case when location = 'Israel' then people_fully_vaccinated else 0 end) as "Israel"
where location in ('Australia','United States','France','Israel')
group by date;
SELECT
date,
people_fully_vaccinated AS 'Australia'
FROM vaccinations
WHERE location = 'Australia';
SELECT
date,
people_fully_vaccinated AS 'United States'
FROM vaccinations
WHERE location = 'United States';
SELECT
date,
people_fully_vaccinated AS 'France'
FROM vaccinations
WHERE location = 'France';
SELECT
date,
people_fully_vaccinated AS 'Israel'
FROM vaccinations
WHERE location = 'Israel';
您已经将位置作为国家/地区名称。所以不需要 select 列 people_fully_vaccinated
如果您想按特定国家/地区进行过滤,请使用以下内容:
SELECT date
,location
FROM vaccinations
WHERE location = 'Australia'
OR location = 'United States'
OR location = 'France'
OR location = 'Israel'
如果你想得到全部,那么使用下面这个:
SELECT date,location FROM vaccinations;
如果您不关心每个国家/地区的数据是否在不同的行中,您可以使用:
select date,
location,
people_fully_vaccinated
from vaccinations
where location in ('Australia','United States','France','Israel');
如果您希望每个国家/地区的数字在每个日期出现在同一行,您可以使用:
select date,
sum(case when location = 'Australia' then people_fully_vaccinated else 0 end) as "Australia",
sum(case when location = 'United States' then people_fully_vaccinated else 0 end) as "United States",
sum(case when location = 'France' then people_fully_vaccinated else 0 end) as "France",
sum(case when location = 'Israel' then people_fully_vaccinated else 0 end) as "Israel"
where location in ('Australia','United States','France','Israel')
group by date;