Sqlite 在sql中不返回右和,其中表1中的ID列是通过视图创建的
我有一个很大的数据库,表1和表2是通过id连接的,我不能做总分 表1Sqlite 在sql中不返回右和,其中表1中的ID列是通过视图创建的,sqlite,Sqlite,我有一个很大的数据库,表1和表2是通过id连接的,我不能做总分 表1 code id 1 12345 1 67533 2 87654 3 65432 表2 id score 12345 60 67533 50 87654 32 65432 67 87654 45 输出 code id score 1 12345 60 1 67533 50 2
code id
1 12345
1 67533
2 87654
3 65432
表2
id score
12345 60
67533 50
87654 32
65432 67
87654 45
输出
code id score
1 12345 60
1 67533 50
2 87654 77
3 65432 67
我使用了以下代码:
SELECT
t1.code,t1.id,p.score
from
(select t2.id,
sum(t2.score)
from
table t2
group by
id) as p
from
table t1
groupby
t1.code,t1.id,p.score
假设您的表名为
table1
和table2
,请使用以下命令:
SELECT t1.code, t1.id, sum(t2.score)
from table1 t1 join table2 t2 on t1.id = t2.id
group by t2.id
order by code;
请参见表t1中的我的列id存储为视图。所以我不知道当其中一列在VIEW中时如何连接两个表。您尝试过这个查询吗?请编辑您的问题,以包括您尝试过的查询结果,并包括所有相关信息,以便回答的人能够给出最合适的答案。