我有一些失败及其发生的数据。我想根据事件中的范围对这些数据进行分组。 EG. >500 Wheel alignment, dpf muffler assy
范围将是10秒。 EG. >=500, 490-500, 480-490.
对不起我之前没有提到,我正在使用excel 2007来做到这一点! :(((
Failures Occurences
WHEEL ALIGNMENT (ADJ) 588
DPF MUFFLER ASSY (R/SERVICE/I) 557
ADJUST ALL BRAKES (ADJ) 436
V-BELT(ALTERNATOR/FAN/COMPRESSOR) (R/I) 402
BATTERY (R/I) 380
FRT BRAKE SHOE & LINING ASSY (R/I) 375
ELECTRICAL REPAIR 270
CLUTCH OVERHAUL 252
STVE & GBL SERVICE PACKAGE 247
答案 0 :(得分:0)
您可以创建并填充范围表(如果需要,可灵活更改范围)
CREATE TABLE failure_ranges (range_start INT, range_end INT);
然后你可以使用这样的查询( MySql 的版本)
SELECT CONCAT(r.range_start, '-', r.range_end) `range`,
GROUP_CONCAT(f.failures ORDER BY f.occurences DESC) failures
FROM failures f JOIN failure_ranges r
ON f.occurences BETWEEN r.range_start AND r.range_end
GROUP BY r.range_start, r.range_end
示例输出:
| RANGE | FAILURES | ------------------------------------------------------------------- | 241-250 | STVE & GBL SERVICE PACKAGE | | 251-260 | CLUTCH OVERHAUL | | 261-270 | ELECTRICAL REPAIR | | 371-380 | BATTERY (R/I),FRT BRAKE SHOE & LINING ASSY (R/I) | | 401-410 | V-BELT(ALTERNATOR/FAN/COMPRESSOR) (R/I) | | 431-440 | ADJUST ALL BRAKES (ADJ) | | 500-999 | WHEEL ALIGNMENT (ADJ),DPF MUFFLER ASSY (R/SERVICE/I) |
以下是 SQLFiddle 演示( MySql )