ERROR: Subquery evaluated to more than one row in Proc SQL
ERROR: Subquery evaluated to more than one row in Proc SQL
我有一个table-
Name Job Group Profession
John Engineering Yes
Shawn Biology Yes
Meg Biology No
Mike Engineering Yes
Meg Biology Yes
John Engineering Yes
Mike Biology Yes
John Engineering Yes
Meg Biology Yes
我想计算与工作组对应的相同名称的职业(是或否)。所以我想要的输出是 -
输出
Name Engineering Biology
John 2 1
Mike 1 1
Shawn 1
Meg 2
我尝试使用此代码但没有成功 -
CREATE TABLE Profile AS
SELECT P.Name
,sum(P.Profession = "Yes") as Engineering_Yes
,sum(P.Profession = "Yes") as Engineering_No
,sum(P.Profession = "No") as Biology_Yes
,sum(P.Profession = "No") as Biology_Yes
FROM Profile P
我尝试使用联合 select 添加作业组列,但没有成功
我是 Proc 的新手 SQL.I 试图搜索相同的示例,但找不到 Proc SQL 的示例。请帮忙。
好吧,你可以使用 GROUP BY
:
CREATE TABLE Profile AS
SELECT P.Name,
sum(case when P.Job_Group = 'Engineering' and P.Profession = 'Yes' and then 1 else 0 end) as Engineering_Yes,
sum(case when P.Job_Group = 'Engineering' and P.Profession = 'No' then 1 else 0 end) as Engineering_No,
sum(case when P.Job_Group = 'Biology' and P.Profession = 'Yes' then 1 else 0 end) as Biology_Yes,
sum(case when P.Job_Group = 'Biology' and P.Profession = 'No' then 1 else 0 end) as Biology_No
FROM Profile P
GROUP BY P.Name;
select P.Name,
count(case when "Job Group" = 'Engineering' then 1 end) as Engineering,
count(case when "Job Group" = 'Biology' then 1 end) as Biology,
from Profile P
where Profession = 'Yes'
group by Name
我有一个table-
Name Job Group Profession
John Engineering Yes
Shawn Biology Yes
Meg Biology No
Mike Engineering Yes
Meg Biology Yes
John Engineering Yes
Mike Biology Yes
John Engineering Yes
Meg Biology Yes
我想计算与工作组对应的相同名称的职业(是或否)。所以我想要的输出是 -
输出
Name Engineering Biology
John 2 1
Mike 1 1
Shawn 1
Meg 2
我尝试使用此代码但没有成功 -
CREATE TABLE Profile AS
SELECT P.Name
,sum(P.Profession = "Yes") as Engineering_Yes
,sum(P.Profession = "Yes") as Engineering_No
,sum(P.Profession = "No") as Biology_Yes
,sum(P.Profession = "No") as Biology_Yes
FROM Profile P
我尝试使用联合 select 添加作业组列,但没有成功
我是 Proc 的新手 SQL.I 试图搜索相同的示例,但找不到 Proc SQL 的示例。请帮忙。
好吧,你可以使用 GROUP BY
:
CREATE TABLE Profile AS
SELECT P.Name,
sum(case when P.Job_Group = 'Engineering' and P.Profession = 'Yes' and then 1 else 0 end) as Engineering_Yes,
sum(case when P.Job_Group = 'Engineering' and P.Profession = 'No' then 1 else 0 end) as Engineering_No,
sum(case when P.Job_Group = 'Biology' and P.Profession = 'Yes' then 1 else 0 end) as Biology_Yes,
sum(case when P.Job_Group = 'Biology' and P.Profession = 'No' then 1 else 0 end) as Biology_No
FROM Profile P
GROUP BY P.Name;
select P.Name,
count(case when "Job Group" = 'Engineering' then 1 end) as Engineering,
count(case when "Job Group" = 'Biology' then 1 end) as Biology,
from Profile P
where Profession = 'Yes'
group by Name