1

我有一些失败及其发生的数据。我想根据出现的范围对这些数据进行分组。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
4

1 回答 1

0

You can create and populate a ranges table (to be flexible in changing ranges if you need to)

CREATE TABLE failure_ranges (range_start INT, range_end INT);

Then you can use a query like this (a version for 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

Sample output:

|   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) |

Here is SQLFiddle demo (MySql)

于 2013-06-28T05:40:15.060 回答