如何在大型数据集中处理sql中的日期

时间:2017-01-16 09:49:06

标签: sql-server

我是SQL的新手我需要帮助解决下面的语法/想法。

我在表格中有以下格式的数据

PLANT   MATERIAL              COST          FROM
2461    000000000029060405   212.920    16-01-2017
2461    000000000029060405   217.301    17-03-2017
2461    000000000029060405   206.900    16-05-2017
2461    000000000029060405   210.400    15-07-2017
2461    000000000029060405   206.900    13-09-2017
2461    000000000029060405   210.400    12-11-2017
2461    000000000029060405   206.900    11-01-2018
2461    000000000029060405   210.400    10-07-2018
2461    000000000029060405   206.900    08-09-2018
2461    000000000029060405   210.400    07-11-2018
2461    000000000029060405   206.900    06-01-2019
2461    000000000029060405   210.400    07-03-2019
2461    000000000029060405   206.900    06-05-2019
2461    000000000029060405   206.900    01-01-2020
2461    000000000029060405   210.400    01-03-2020

我想要一种语法,可以按以下格式提供每月费用

PLANT   MATERIAL             COST       DATE
2462    000000000029060405   212.920    01-02-2017
2463    000000000029060405   212.920    02-02-2017
2464    000000000029060405   217.301    03-02-2017
2465    000000000029060405   217.301    04-02-2017
2466    000000000029060405   206.900    05-02-2017
2467    000000000029060405   206.900    06-02-2017
2468    000000000029060405   210.400    07-02-2017
2469    000000000029060405   210.400    08-02-2017
2470    000000000029060405   206.900    09-02-2017
2471    000000000029060405   206.900    10-02-2017
2472    000000000029060405   210.400    11-02-2017
2473    000000000029060405   210.400    12-02-2017
2474    000000000029060405   206.900    13-02-2017
2475    000000000029060405   206.900    14-02-2017
2476    000000000029060405   206.900    15-02-2017
2477    000000000029060405   206.900    16-02-2017
2478    000000000029060405   206.900    17-02-2017
2479    000000000029060405   206.900    18-02-2017
2480    000000000029060405   210.400    19-02-2017
2481    000000000029060405   210.400    20-02-2017
2482    000000000029060405   206.900    21-02-2017
2483    000000000029060405   206.900    22-02-2017
2484    000000000029060405   210.400    23-02-2017
2485    000000000029060405   210.400    24-02-2017
2486    000000000029060405   206.900    25-02-2017
2487    000000000029060405   206.900    26-02-2017
2488    000000000029060405   210.400    27-02-2017
2489    000000000029060405   210.400    28-02-2017
2490    000000000029060405   206.900    01-03-2017
2491    000000000029060405   206.900    02-03-2017
2492    000000000029060405   206.900    03-03-2017
2493    000000000029060405   206.900    04-03-2017
2494    000000000029060405   206.900    05-03-2017
2495    000000000029060405   206.900    06-03-2017
2496    000000000029060405   206.900    07-03-2017
2497    000000000029060405   206.900    08-03-2017
2498    000000000029060405   206.900    09-03-2017
2499    000000000029060405   206.900    10-03-2017
2500    000000000029060405   210.400    11-03-2017
2501    000000000029060405   210.400    12-03-2017
2502    000000000029060405   210.400    13-03-2017
2503    000000000029060405   210.400    14-03-2017
2504    000000000029060405   210.400    15-03-2017
2505    000000000029060405   210.400    16-03-2017

1 个答案:

答案 0 :(得分:0)

我想您想按工厂和日期对数据进行分组。请尝试以下代码:

Select Plant,Material,Sum(Cost),Date
From Tablename 
Group By Plant,Material,Date
order by Date