SQL简单减法查询 [英] SQL Simple Subtraction Query

查看:56
本文介绍了SQL简单减法查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库.它包含2个表.让我称它们为表 A 和表 B.

I have a Database. It contains 2 Tables. Let me call them Table A and Table B.

表 A 内容:

  1. 日期
  2. 供应商名称
  3. 已交付货物名称
  4. 已交付货物的数量,只需输入成分 A(数值)

表 B 内容:

  1. 生产日期
  2. 产品名称
  3. 成分 A

我真正想要的是:

查询表 A,第 4 列减去(减法)表 B,第 3 列.

Query with Table A, Column 4 minus (Subtraction) Table B, Column 3.

额外说明:

我一直在向一位友好的程序员提出这个问题.他建议我完成 w3schools.com 的在线课程,我也是这样做的.他还假设减法应该属于某个加入"函数.

I have been asking this question to a friendly programmer. He adviced me to go through the onlince course of w3schools.com which I did. He also assumed the subtraction should belong under a certain 'Join' function.

我也一直在谷歌和搜索 Stackoverflow.没有结果.即便如此,我还是要提一下,我可能找不到结果,因为我的英语很差.

I have also been googling and searching Stackoverflow. With no results. Even tho, I need to mention that I maybe lack finding the results because my English is quite poor.

如果我的英语很差并且我的问题是/措辞不当,我想真诚地道歉.英语不是我的母语.

I want to sincerely apologise, if my English is poor and if my question was / is poorly phrased. English is not my native language.

如果无法直接提供帮助,我愿意并渴望学习.如果您有任何来源可以让我在与数据库相关的查询(例如 MS Access 或 OOo Base)中了解简单的数学知识,请随时向我推荐优秀的信息网站和/或课程.

If direct help is not possible, I am willing and eager to learn. If you have any sources where I can learn about simple mathematics in Querys related to Databases (Such as MS Access or OOo Base) than feel free to refer me to good and informational websites and / or courses.

真诚的问候柔软

系统信息:

  • Windows 7 - 64 位 - 家庭版及其所有更新
  • OpenOffice.org 3.3.0 - OOO330m20(内部版本:9567)

未将 OOo 升级到最新版本的原因:与以前的脚本软件的兼容性问题.而且在工作中修复 4.0 及更高版本的这些问题的时间太少"了.

Reason for not upgrading OOo to latest version: Compatibility Issues with previous scripted software. And too 'less' time at the job to fix those issues for Version 4.0 and later.

推荐答案

你可以只在 SQL 中使用数学

You can just use math in SQL

SELECT 
    (a.column_4 - b.column_3) as subtracted_value 
FROM 
    TABLE_A as a 
JOIN 
    TABLE_B as b ON a.id = b.table_a_id

subtracted_value"应该是表a的第4列的值减去表b的第3列的值.您需要使用 id 连接表,以便您可以看到 TABLE A 的哪一行属于 TABLE B 的哪一行.

"subtracted_value" should be the value of column 4 of table a minus column 3 of table b here. You need to join the tables using an id so you can see which row of TABLE A belongs to which row of TABLE B.

在这个例子中,我将表 A 中的 id 称为id",将表 B 中的指针称为指向表 A 的 id 的指针table_a_id".所以表A中的id"和表B中的table_a_id"在属于同一行时需要相等.

In this example I called the id in TABLE A "id" and the pointer in TABLE B to the id of TABLE A "table_a_id". So "id" in TABLE A and "table_a_id" in TABLE B need to be equal when they belong to the same row.

值得一看:http://www.w3schools.com/sql/sql_join.asp

这篇关于SQL简单减法查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆