连接两个sql表的结果
我想从按相同规则分组的两个表中获取结果,这些表在一个选择中连接在一起。
我有表 1
create table person AS
id INTEGER,
gender INTEGER,
state VARCHAR2
name VARCHAR2
surname VARCHAR2
表 2
create table sampletest as
person_id FOREIGN KEY To person.id
result INTEGER
表 3
create table examtest as
person_id FOREIGN KEY to person.id
examresult INTEGER
我想
按状态 | 获取此输出组按性别分组 |计数(考试结果>0) | count(result>0 and result<4)
我尝试了类似的方法
select state,gender,count(e.examresult),count(s.result) where
p.id=s.person_id and p.id=e.person_id and
s.result>0 and s.result<4 and
e.examresult>0 group by state,gender
,但得到的结果相互依赖。如何将独立结果纳入一项选择?
I would like to get results from two tables grouped by same rules joined together in one select.
I have table 1
create table person AS
id INTEGER,
gender INTEGER,
state VARCHAR2
name VARCHAR2
surname VARCHAR2
table 2
create table sampletest as
person_id FOREIGN KEY To person.id
result INTEGER
table 3
create table examtest as
person_id FOREIGN KEY to person.id
examresult INTEGER
I would like to get this output
group by state | group by gender | count(examresult>0) | count(result>0 and result<4)
I tried something like this
select state,gender,count(e.examresult),count(s.result) where
p.id=s.person_id and p.id=e.person_id and
s.result>0 and s.result<4 and
e.examresult>0 group by state,gender
but i get results that are dependent on each other. How do i get independent results into one select?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
构建子选择
Build sub-selects