我有3张桌子彼此没有关系

编程入门 行业动态 更新时间:2024-10-24 03:20:53
本文介绍了我有3张桌子彼此没有关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

表格是这样的数据

the tables habe the data like this

create table t1 (a1 int,b1 int ,c1 int) create table t2 (a2 int,b2 int ,c2 int) create table t3 (a3 int,b3 int ,c3 int) insert into t1 values(1,5,6),(5,8,4) insert into t2 values(5,8,9),(1,4,4) insert into t2 values(6,2,7),(7,6,0)

i希望输出如下

i want the output like below

(c1+c2+c3) ---------- 22 8

我的尝试:

What I have tried:

WITH b1(a1, b1,c1) AS (select * from t1), b2(a2,b2,c2) AS (select * from t2), b3(a3,b3,c3)as (select * from t3), b4(csjdls) as (( select c1+c2+c3 from b1,b2,b3)) SELECT csjdls FROM b4

i尝试了以上它当我只有一张唱片只有一张唱片时工作正常 但我想要多张唱片

i tried the above it iw working fine when only table having only one record but i want to for multiple records

推荐答案

试试这个: Try this: SELECT SUM(c) AS TotalC FROM ( SELECT c1 AS c FROM t1 UNION ALL SELECT c2 AS c FROM t2 UNION ALL SELECT c3 AS c FROM t3 ) AS t

更多推荐

我有3张桌子彼此没有关系

本文发布于:2023-10-28 18:30:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537430.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我有   桌子   关系

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!