Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.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-摘要报告-删除重复项-列总数_Mysql - Fatal编程技术网

Mysql-摘要报告-删除重复项-列总数

Mysql-摘要报告-删除重复项-列总数,mysql,Mysql,我在Mysql中有一个记录设备及其关系的表 单个设备可以与多个对象相关。我想唯一的设备ID,所以我不计算设备多次,并提供所有设备的总容量 Array | Capacity | deviceId | Assignment 4321 1024 3eb esx1 4321 1024 3eb esx2 4321 1024 3eb esx3 4321 28672 3ec w

我在Mysql中有一个记录设备及其关系的表

单个设备可以与多个对象相关。我想唯一的设备ID,所以我不计算设备多次,并提供所有设备的总容量

Array | Capacity | deviceId | Assignment
 4321    1024       3eb        esx1
 4321    1024       3eb        esx2
 4321    1024       3eb        esx3
 4321    28672      3ec        win1
 4321    61440      9f1        unassigned
我想要一份类似下面的报告

Array | Capacity 
 4321    91136
我尝试了
按设备ID从表组中选择sum(Capacity)
,但这并没有给出预期的结果

如有任何见解,我们将不胜感激。

假设数据重复(前3列),如问题所示:

create table table1
(   id int auto_increment primary key,
    Array int not null,
    Capacity int not null,
    deviceId varchar(100) not null,
    Assignment varchar(100) not null
);
truncate table table1;
insert table1(array,capacity,deviceId,assignment) values 
(4321,1024,'3eb','blah'),
(4321,1024,'3eb','blah'),
(4321,1024,'3eb','blah'),
(4321,28672,'3ec','blah'),
(4321,61440,'9f1','blah');

select Array,sum(Capacity) as Capacity 
from 
( select distinct Array,Capacity,deviceId
  from table1
) xxx 
group by Array;

+-------+----------+
| Array | Capacity |
+-------+----------+
|  4321 |    91136 |
+-------+----------+
假设重复数据(前3列),如问题所示:

create table table1
(   id int auto_increment primary key,
    Array int not null,
    Capacity int not null,
    deviceId varchar(100) not null,
    Assignment varchar(100) not null
);
truncate table table1;
insert table1(array,capacity,deviceId,assignment) values 
(4321,1024,'3eb','blah'),
(4321,1024,'3eb','blah'),
(4321,1024,'3eb','blah'),
(4321,28672,'3ec','blah'),
(4321,61440,'9f1','blah');

select Array,sum(Capacity) as Capacity 
from 
( select distinct Array,Capacity,deviceId
  from table1
) xxx 
group by Array;

+-------+----------+
| Array | Capacity |
+-------+----------+
|  4321 |    91136 |
+-------+----------+

这类问题可能是不良(即非标准化)设计的症状。同一个deviceid是否可以同时拥有不同的容量?deviceid的容量始终相同,只是多个assignment SSO容量应在单独的表中。此类问题可能是设计不佳(即非标准化)的症状。同一个deviceid能否同时拥有不同的容量?deviceid的容量始终相同,只是多个assignmentSSO容量应该在一个单独的表中。太好了!谢谢你,我悲伤孤独的回答,被世界遗忘了。太好了!谢谢你,我悲伤孤独的回答,被世界遗忘了。