2 个表的 3 个值之间的差异

发布于 2025-01-05 05:12:19 字数 390 浏览 0 评论 0原文

我有 2 个表,例如

id  att1 att2
1   34    56
2   45    12
3   34    11


id  att1 att2
1   14    10
2   25    2
3   14    10

如何获取 3 个值之间的差异,例如

id      att1      att2
1-1=0  34-14=20  56-10=46
2-2=0  45-25=20  12-2 =10  
3-3=0  34-14=20  11-10=1 


SELECT A.id-B.id, A.att1-B.att1,A.att2-B.att2 from TABLEA as A join TABLEB as B...

I have 2 tables like

id  att1 att2
1   34    56
2   45    12
3   34    11


id  att1 att2
1   14    10
2   25    2
3   14    10

How to get the diference between the 3 values like

id      att1      att2
1-1=0  34-14=20  56-10=46
2-2=0  45-25=20  12-2 =10  
3-3=0  34-14=20  11-10=1 


SELECT A.id-B.id, A.att1-B.att1,A.att2-B.att2 from TABLEA as A join TABLEB as B...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玉环 2025-01-12 05:12:19

你不会真的想从一个 id 中减去另一个 id,对吗?

SELECT
  A.id,
  A.att1 - B.att1,
  A.att2 - B.att2
FROM
  A JOIN B ON A.id = B.id

You don't really want to subtract one id from another, do you?

SELECT
  A.id,
  A.att1 - B.att1,
  A.att2 - B.att2
FROM
  A JOIN B ON A.id = B.id
池予 2025-01-12 05:12:19

不确定您在寻找什么您在问题中尚未提供的内容。你的意思是这样的吗?

SELECT
    CAST(A.id AS VARCHAR(200)) + '-' +  CAST(B.id AS VARCHAR(200)) + '=' + CAST(A.id - B.id AS VARCHAR(200)) id
    ,CAST(A.att1 AS VARCHAR(200)) + '-' +  CAST(B.att1 AS VARCHAR(200)) + '=' + CAST(A.att1 - B.att1 AS VARCHAR(200)) att1
    ,CAST(A.att2 AS VARCHAR(200)) + '-' +  CAST(B.att2 AS VARCHAR(200)) + '=' + CAST(A.att2 - B.att2 AS VARCHAR(200)) att2
FROM
    TABLEA A
    INNER JOIN TABLEB B ON A.id = B.id

Not sure what you're looking for that you didn't already supply in your question. Did you mean something like this?

SELECT
    CAST(A.id AS VARCHAR(200)) + '-' +  CAST(B.id AS VARCHAR(200)) + '=' + CAST(A.id - B.id AS VARCHAR(200)) id
    ,CAST(A.att1 AS VARCHAR(200)) + '-' +  CAST(B.att1 AS VARCHAR(200)) + '=' + CAST(A.att1 - B.att1 AS VARCHAR(200)) att1
    ,CAST(A.att2 AS VARCHAR(200)) + '-' +  CAST(B.att2 AS VARCHAR(200)) + '=' + CAST(A.att2 - B.att2 AS VARCHAR(200)) att2
FROM
    TABLEA A
    INNER JOIN TABLEB B ON A.id = B.id
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文