У меня есть две таблицы, к которым я хочу присоединиться и суммировать и считать в одном выражении.
create table t1 (
code int(10) primary key,
Typ varchar(10) not null,
Status int(10) not null);
create table t2 (
code int(10) primary key,
Typ varchar(10) not null,
SubTyp varchar(10) not null);
insert into t1 values (1,'A',1);
insert into t1 values (2,'B',1);
insert into t1 values (3,'A',1);
insert into t1 values (4,'B',1);
insert into t1 values (5,'A',1);
insert into t1 values (6,'B',1);
insert into t2 values (1,'A','A1');
insert into t2 values (2,'A','A1');
insert into t2 values (3,'A','A2');
insert into t2 values (4,'B','B1');
insert into t2 values (5,'B','B2');
insert into t2 values (6,'B','B3');
Начиная с t1, я хочу получить сумму на тип, а с t2 - различное количество подтипов на тип. Результаты, которые мне нужно достичь, следующие:
Sum Typ A Sum Typ B Count Typ A Count Typ B Ratio A (count/sum) Ratio A (count/sum)
3 3 2 3 0.666666667 1
Я могу суммировать и считать на одном столе, но не могу, когда мне нужно присоединиться к ним.