Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL中的组合表和求和表_Mysql_Sql_Join - Fatal编程技术网

Mysql SQL中的组合表和求和表

Mysql SQL中的组合表和求和表,mysql,sql,join,Mysql,Sql,Join,我在sql查询方面遇到问题,正在寻求帮助 我有三张桌子(表一、表二、表三) 从表1中,我有a/b列 从表2中我有c/d列 从表3中,我有e/f列 我将a/c列合并为g列,将d/b列合并为h列 现在,我想将列e与列h(它们具有相同的名称)匹配,并对按列f分组的列g求和。接下来,我想对它进行降序排序 这是我到目前为止所拥有的 select (one.a + two.c), (one.b + two.d) from table_1 one, table_2 two inner join table

我在sql查询方面遇到问题,正在寻求帮助

我有三张桌子(表一、表二、表三)

  • 从表1中,我有a/b列
  • 从表2中我有c/d列
  • 从表3中,我有e/f列
我将a/c列合并为g列,将d/b列合并为h列

现在,我想将列e与列h(它们具有相同的名称)匹配,并对按列f分组的列g求和。接下来,我想对它进行降序排序

这是我到目前为止所拥有的

select (one.a + two.c), (one.b + two.d)
from table_1 one, table_2 two
inner join table_3
on (one.b + two.d) = table_3.e

我得到一个错误“无效标识符”,我认为这是由于没有(1.b+2.d)的组合名称造成的。是否有人知道如何将这两个元素相加,然后对g列求和?

我认为您的问题可能是您的表使用了以数字字符开头的标识符。尝试使用以字母数字字符开头的标识符:

select (t1.a + 2.c), (t1.b + 2.d)
from table_1 t1, table_2 t2
inner join table_3
on (t1.b + t2.d) = table_3.e

我的表名实际上不是1,2,3。对不起,我在发布之前更改了它们。你说的“合并”是指“添加”吗?这就是SQL所做的。如果您是指字符串连接,请使用
CONCAT
函数。我将一列长度为n,另一列长度为m,并将它们转换为一列长度为n+m
CONCAT(one.a,two.c)