当attributeid=5和attributeid=197时,我需要rawvalue>0的数据,如果是attributeid=5或attributeid=197,我可以得到它,但是我得到2个driveid,如果我按驱动器id分组,我就错过了信息
例子:
SELECT rawvalue, driveid, attributeid
from labtech.smartattributes
where rawvalue>0 and attributeid = 197 or rawvalue>0 and attributeid= 198
# rawvalue, driveid, attributeid
'1', '186', '197'
'8', '488', '198'
'8', '489', '198'
'8', '919', '197'
'8', '919', '198'
'1', '1000', '197'
'3', '1129', '197'
'3', '1129', '198'
'1', '1335', '197'
'1', '1335', '198'
正如你所看到的,我在driveid端有多余的信息
因此,如果我分组,我得到:
# rawvalue, driveid, attributeid
'1', '186', '197'
'8', '919', '197'
'1', '1000', '197'
'3', '1129', '197'
'1', '1335', '197'
'37', '1389', '197'
'1', '1545', '197'
'6', '2228', '197'
'8', '2390', '197'
'8', '2391', '197'
'8', '2392', '197'
'1', '3068', '197'
'1', '3069', '197'
'39', '3402', '197'
'100663551', '3441', '19'
'1', '3665', '197'
但是,我再也看不出这两个属性是否都存在了
最终目标:我只需要在两个属性都存在(5和197)的情况下显示,但是,我不想显示冗余的driveid值这可能吗?
链接到数据库:https://www.db-fiddle.com/f/nd7jrmtb7mbype43zrfbkj/0#&togetherjs=4s61q2qptf
我找到了我要找的东西:
潜在解决方案:
从labtech.smartattributes中选择group_concat(rawvalue)、driveid、group_concat(attributeid),其中rawvalue>0和attributeid in('5','198')或rawvalue>0和attributeid in('5','187')或rawvalue>0和attributeid in('5','188')或rawvalue>0和attributeid in('5','197')或rawvalue>0和attributeid in('187','188')或rawvalue>0且attributeid在('187','197')或rawvalue>0且attributeid在('187','198')或rawvalue>0且attributeid在('188','197')或rawvalue>0且attributeid在('188','198')组中,按count(*)>=3的driveid
****我添加了更多,因为我希望包含一定数量的属性
输出:
组\u concat(rawvalue)、driveid、组\u concat(attributeid)
10,7,7, 4583, 188,197,198
10,8,8, 6101, 188,197,198
100,1,8, 11311, 187,188,197
100,1,8, 11312, 187,188,197
12,9,11, 12976, 5,187,198
131072,2162716,8, 2390, 187,188,197
131072,2162716,8, 2391, 187,188,197
131072,2162716,8, 2392, 187,188,197
131078,851978,3, 6549, 5,187,188
131078,9175040,2, 6471, 5,187,188
176,3,8, 488, 5,188,198
176,3,8, 489, 5,188,198
179,71,8,8, 5134, 187,188,197,198
21368000,2162776,62062592,24, 4733, 5,187,188,197
2809,239,3,3, 1129, 5,188,197,198
31195657,27459700,2031641,16, 6473, 5,187,188,197
314,804,11, 23905, 5,197,198
32505856,1966569,6, 21160, 187,188,197
32505856,1966569,6, 21161, 187,188,197
327685,27,145179, 23641, 5,187,188
327685,27,145179, 23642, 5,187,188
3316,1,1, 23604, 187,197,198
3322,1,1, 1335, 187,197,198
4,165,22, 3274, 5,187,188
4,165,22, 3275, 5,187,188
4,165,22, 3281, 5,187,188
45,231,1, 17217, 5,187,198
49676288,1966628,6, 21159, 187,188,197
49676288,1966628,6, 21188, 187,188,197
49676288,1966628,6, 21189, 187,188,197
636,1,1703976,19,19, 23781, 5,187,188,197,198
65544,196608,27, 3104, 5,187,188
65544,196608,27, 3105, 5,187,188
65544,196608,27, 3106, 5,187,188
65552,29491200,786432,128, 19260, 5,187,188,197
65552,29491200,786432,128, 19262, 5,187,188,197
65552,29491200,786432,128, 19264, 5,187,188,197
72,1,8, 23583, 187,188,197
774,169,1,1, 3998, 187,188,197,198
786448,236,240, 12743, 5,197,198
8,34608,327685,8,8, 919, 5,187,188,197,198
8,374,1, 12266, 5,187,198
链接到相关文章:在同一列上使用多个where条件进行选择
暂无答案!
目前还没有任何答案,快来回答吧!