Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 没有嵌套选择,我无法执行此查询_Mysql_Sql - Fatal编程技术网

Mysql 没有嵌套选择,我无法执行此查询

Mysql 没有嵌套选择,我无法执行此查询,mysql,sql,Mysql,Sql,我有一个具有三个属性的表(标识者、id_law、姓氏、投票)。 投票可以有三种价值观:赞成、反对或弃权 我无法执行此查询: 你想知道每一条法律,因为有赞成票、反对票和弃权票 选择必须是唯一的,不允许嵌套选择 create table house_law ( -- the proposed up for vote law_id varchar(50) NOT NULL PRIMARY KEY, descr varchar(255) ); insert house_law (law_id,de

我有一个具有三个属性的表(标识者、id_law、姓氏、投票)。 投票可以有三种价值观:赞成、反对或弃权

我无法执行此查询: 你想知道每一条法律,因为有赞成票、反对票和弃权票

选择必须是唯一的,不允许嵌套选择

create table house_law
(   -- the proposed up for vote
law_id varchar(50) NOT NULL PRIMARY KEY,
descr varchar(255)
);

insert house_law (law_id,descr) values ('HR-109B','Forbid driving near turtles');

create table house_rep
(   -- a session is say Monday to Friday, captures a start date
rep_id int not null PRIMARY KEY,
fullname varchar(80) not null,
party varchar(80)
);

insert house_rep (rep_id,fullname,party) values (1001,'Thomas Jefferson','Whig');
insert house_rep (rep_id,fullname,party) values (800,'fred','Abstain Party');
insert house_rep (rep_id,fullname,party) values (700,'stan','Abstain Party');

create table votes_cast
(law_id varchar(50) not null,
rep_id int not null,
the_vote varchar(20) -- for, against, abstain
);

insert votes_cast (law_id,rep_id,the_vote) values ('HR-109B',1001,'against');
insert votes_cast (law_id,rep_id,the_vote) values ('HR-109B',800,'abstain');
insert votes_cast (law_id,rep_id,the_vote) values ('HR-109B',700,'abstain');

-- get the results

select l.law_id,
l.descr,
sum(case when v.the_vote='for' then 1 else 0 end) for_votes,
sum(case when v.the_vote='against' then 1 else 0 end) against_votes,
sum(case when v.the_vote='abstain' then 1 else 0 end) abstain_votes
from house_law l
join votes_cast v
on v.law_id=l.law_id
group by l.law_id -- or a where close for 1 law in particular
输出: 赞成、反对、弃权


HR-109B禁止在海龟01附近驾驶2

你的问题问得很含糊。记住,看问题的人除了你提供的信息之外,根本不知道你在做什么。示例数据、期望的结果、表结构和示例查询无疑有助于澄清问题。请发布一些示例数据以及您试图获得的数据结果,好吗?这可能有助于我们理解这个问题。谢谢,这正是我想要的!