【发布时间】:2010-11-18 19:06:48
【问题描述】:
我想从按相同规则分组的两个表中获取结果,并在一次选择中连接在一起。
我有表 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)|计数(结果>0 和结果
我试过这样的
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
但我得到的结果相互依赖。如何将独立结果放入一个选择中?
【问题讨论】:
标签: sql postgresql