期间总和

时间:2019-09-25 22:55:18

标签: sql teradata-sql-assistant

我对行数有一些疑问。我在Teradata SQL Assistant中具有以下数据集:

`    this is the second part of the code.------------------DEFAULT_SKIN---------------------{}

/* --- arrows -- */

.ug-arrow-left.ug-skin-default,
.ug-arrow-right.ug-skin-default{
    width:15px;
    height:30px;
    background-image:url('images/slider_arrow_left.png');
    background-position:0px 0px;
}

.ug-arrow-right.ug-skin-default{
    background-image:url('images/slider_arrow_right.png');
}

.ug-arrow-left.ug-skin-default.ug-arrow-hover,
.ug-arrow-right.ug-skin-default.ug-arrow-hover{
    background-position:0px -30px;
}

.ug-arrow-left.ug-skin-default.ug-arrow-disabled,
.ug-arrow-right.ug-skin-default.ug-arrow-disabled{
    background-position:0px -60px;
}

/* --- bullets -- */

.ug-bullets.ug-skin-default .ug-bullet{
    width:15px;
    height:15px;
    background-image:url('images/slider_bullets.png');
    background-position:top left;
    margin-left:5px;
}

.ug-bullets.ug-skin-default .ug-bullet.ug-bullet-active{
    background-position:bottom left;
}

.ug-bullets.ug-skin-default.ug-bullets-gray .ug-bullet{ 
    background-image:url('images/tile_bullets_gray.png');
}

.ug-bullets.ug-skin-default.ug-bullets-blue .ug-bullet{ 
    background-image:url('images/tile_bullets_blue.png');
}

.ug-bullets.ug-skin-default.ug-bullets-brown .ug-bullet{ 
    background-image:url('images/tile_bullets_brown.png');
}

.ug-bullets.ug-skin-default.ug-bullets-green .ug-bullet{ 
    background-image:url('images/tile_bullets_green.png');
}

.ug-bullets.ug-skin-default.ug-bullets-red .ug-bullet{ 
    background-image:url('images/tile_bullets_red.png');
}

.ug-button-tile-navigation{
    width:36px;
    height:36px;
    background-position:top left;
    cursor:pointer;
    float:left;
}

.ug-button-tile-navigation.ug-button-tile-left{
    background-image:url('images/tile_button_left.png');
}

.ug-button-tile-navigation.ug-button-tile-right{
    background-image:url('images/tile_button_right.png');
}

.ug-button-tile-navigation:hover{
    background-position:bottom left;
}

.ug-button-tile-navigation.ug-button-disabled{
    opacity:0.6;
}

.ug-button-tile-navigation.ug-button-disabled:hover{
    background-position:top left;   
}

.ug-button-tile-navigation.ug-button-tile-play{
    background-image:url('images/tile_button_play_pause.png');
    width:35px;
} 

.ug-button-tile-navigation.ug-button-tile-play.ug-pause-icon{
    background-position:bottom left;
} 

.ug-button-tile-navigation.ug-button-tile-play:hover{
    background-position:top left;
} 

.ug-button-tile-navigation.ug-button-tile-play.ug-pause-icon:hover{
    background-position:bottom left;
} 


/* --- play button -- */

.ug-button-play.ug-skin-default{
    position:absolute;
    background-image:url('images/button_playpause.png');
    width:14px;
    height:17px;
    cursor:pointer;
    background-position:0px 0px;
}

.ug-button-play.ug-skin-default.ug-button-hover{
    background-position:0px -17px;  
}

.ug-button-play.ug-skin-default.ug-stop-mode{
    background-position:0px -34px;
}

.ug-button-play.ug-skin-default.ug-stop-mode.ug-button-hover{
    background-position:0px -51px;
}

/* --- fullscreen button -- */

.ug-button-fullscreen.ug-skin-default{
    position:absolute;
    background-image:url('images/button_fullscreen.png');
    width:16px;
    height:16px;
    cursor:pointer;
    background-position:0px 0px;
}

.ug-button-fullscreen.ug-skin-default.ug-button-hover{
    background-position:0px -16px;  
}

.ug-button-fullscreen.ug-skin-default.ug-fullscreenmode{
    background-position:0px -32px;
}

.ug-button-fullscreen.ug-skin-default.ug-fullscreenmode.ug-button-hover{
    background-position:0px -48px;
}


/* --- zoom panel --- */

.ug-zoompanel.ug-skin-default .ug-zoompanel-button{
    background-repeat: no-repeat;
    cursor:pointer;
    height: 23px;
    width: 23px;
    margin-top:5px;
    background-position: 0px 0px;   
}

.ug-zoompanel.ug-skin-default .ug-zoompanel-plus{
    margin-top:0px;
}

.ug-zoompanel.ug-skin-default .ug-zoompanel-plus{
    background-image:url('images/icon_zoom_plus.png');
}

.ug-zoompanel.ug-skin-default .ug-zoompanel-minus{
    background-image:url('images/icon_zoom_minus.png');
}

.ug-zoompanel.ug-skin-default .ug-zoompanel-return{
    background-image:url('images/icon_zoom_back.png');
}

.ug-zoompanel.ug-skin-default .ug-zoompanel-button.ug-button-hover{
    background-position: 0px -23px;
}

.ug-zoompanel.ug-skin-default .ug-zoompanel-button-disabled,
.ug-zoompanel.ug-skin-default .ug-zoompanel-button.ug-button-hover.ug-zoompanel-button-disabled{
    background-position: 0px -46px;
    cursor:default;
}


/* --- Grid Panel Arrows -- */

/*--- down arrow ---*/

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-down.ug-skin-default{
    width:30px;
    height:15px;
    background-position:0px 0px;    
    background-image:url('images/arrow_grid_down.png');
}

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-down.ug-skin-default.ug-button-hover{
    background-position:0px -15px;
}

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-down.ug-skin-default.ug-button-hover.ug-button-disabled,
.ug-gallery-wrapper .ug-grid-panel .grid-arrow-down.ug-skin-default.ug-button-disabled{
    background-position:0px -30px;
}


/*--- up arrow ---*/

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-up.ug-skin-default{
    width:30px;
    height:15px;
    background-position:0px 0px;    
    background-image:url('images/arrow_grid_up.png');
}

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-up.ug-skin-default.ug-button-hover{
    background-position:0px -15px;  
}

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-up.ug-skin-default.ug-button-hover.ug-button-disabled,
.ug-gallery-wrapper .ug-grid-panel .grid-arrow-up.ug-skin-default.ug-button-disabled{
    background-position:0px -30px;
}

/*--- left arrow ---*/

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-left.ug-skin-default{
    width:40px;
    height:40px;
    background-position:0px -40px;
    background-image:url('images/grid_arrow_left.png');
}

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-left.ug-skin-default.ug-button-hover{
    background-position:0px -0px;
}

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-left.ug-skin-default.ug-button-hover.ug-button-disabled,
.ug-gallery-wrapper .ug-grid-panel .grid-arrow-left.ug-skin-default.ug-button-disabled{
    background-position:0px -80px;
}

/*--- right arrow ---*/

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-right.ug-skin-default{
    width:40px;
    height:40px;
    background-position:0px -40px;  
    background-image:url('images/grid_arrow_right.png');
}

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-right.ug-skin-default.ug-button-hover{
    background-position:0px -0px;
}

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-right.ug-skin-default.ug-button-hover.ug-button-disabled,
.ug-gallery-wrapper .ug-grid-panel .grid-arrow-right.ug-skin-default.ug-button-disabled{
    background-position:0px -80px;
}

/*--- left arrow - horizontal panel type ---*/

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-left-hortype.ug-skin-default{
    width:15px;
    height:30px;
    background-image:url('images/slider_arrow_left.png');
    background-position:0px 0px;
}

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-left-hortype.ug-skin-default.ug-button-hover{
    background-position:0px -30px;
}

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-left-hortype.ug-skin-default.ug-button-hover.ug-button-disabled,
.ug-gallery-wrapper .ug-grid-panel .grid-arrow-left-hortype.ug-skin-default.ug-button-disabled{
    background-position:0px -60px;
}


/*--- right arrow - horizontal panel type ---*/

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-right-hortype.ug-skin-default{
    width:15px;
    height:30px;
    background-image:url('images/slider_arrow_right.png');
    background-position:0px 0px;
}

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-right-hortype.ug-skin-default.ug-button-hover{
    background-position:0px -30px;
}

.ug-gallery-wrapper .ug-grid-panel .grid-arrow-right-hortype.ug-skin-default.ug-button-hover.ug-button-disabled,
.ug-gallery-wrapper .ug-grid-panel .grid-arrow-right-hortype.ug-skin-default.ug-button-disabled{
    background-position:0px -60px;
}


/* --- Strip Panel Arrows -- */

/* left and right arrows */

.ug-strip-panel .ug-strip-arrow-left.ug-skin-default,
.ug-strip-panel .ug-strip-arrow-right.ug-skin-default{
    width:25px;
    height:50px;
}

.ug-strip-panel .ug-strip-arrow-left.ug-skin-default .ug-strip-arrow-tip,
.ug-strip-panel .ug-strip-arrow-right.ug-skin-default .ug-strip-arrow-tip{
    background-position:0px 0px;
    background-repeat:no-repeat;
    width:4px;
    height:7px;
}

.ug-strip-panel .ug-strip-arrow-left.ug-skin-default .ug-strip-arrow-tip{
    background-image:url('images/arrows_strip_left.png');
}

.ug-strip-panel .ug-strip-arrow-right.ug-skin-default .ug-strip-arrow-tip{
    background-image:url('images/arrows_strip_right.png');  
}

.ug-strip-panel .ug-strip-arrow-left.ug-skin-default.ug-button-hover .ug-strip-arrow-tip,
.ug-strip-panel .ug-strip-arrow-right.ug-skin-default.ug-button-hover .ug-strip-arrow-tip{
    background-position:0px -7px;
}


/* up and down arrows */

.ug-strip-panel .ug-strip-arrow-up.ug-skin-default,
.ug-strip-panel .ug-strip-arrow-down.ug-skin-default{
    height:25px;
    width:50px;
}

.ug-strip-panel .ug-strip-arrow-up.ug-skin-default .ug-strip-arrow-tip,
.ug-strip-panel .ug-strip-arrow-down.ug-skin-default .ug-strip-arrow-tip{
    background-position:0px 0px;
    background-repeat:no-repeat;
    width:7px;
    height:4px;
}

.ug-strip-panel .ug-strip-arrow-up.ug-skin-default .ug-strip-arrow-tip{
    background-image:url('images/arrows_strip_up.png');
}

.ug-strip-panel .ug-strip-arrow-down.ug-skin-default .ug-strip-arrow-tip{
    background-image:url('images/arrows_strip_down.png');   
}

.ug-strip-panel .ug-strip-arrow-up.ug-skin-default.ug-button-hover .ug-strip-arrow-tip,
.ug-strip-panel .ug-strip-arrow-down.ug-skin-default.ug-button-hover .ug-strip-arrow-tip{
    background-position:-7px 0px;
}

.ug-strip-panel .ug-strip-arrow.ug-skin-default.ug-button-disabled .ug-strip-arrow-tip{
    background-position:0px 0px;
    opacity:0.5;
    filter: alpha(opacity = 50);
}


/* --- Panel Handle Tip -- */

/* left and right handle */
.ug-gallery-wrapper .ug-handle-tip-left.ug-skin-default,
.ug-gallery-wrapper .ug-handle-tip-right.ug-skin-default{
    width:22px;
    height:36px;
    background-image:url('images/grid_handle_black_left.png');
    background-repeat:no-repeat;
    background-position:0px -36px;
}

.ug-gallery-wrapper .ug-handle-tip-right.ug-skin-default{
    background-image:url('images/grid_handle_black_right.png');
    background-position:0px -36px;
}

.ug-gallery-wrapper .ug-handle-tip-left.ug-button-hover.ug-skin-default,
.ug-gallery-wrapper .ug-handle-tip-right.ug-button-hover.ug-skin-default{
    background-position:0px -0px;   
}

.ug-gallery-wrapper .ug-handle-tip-left.ug-skin-default.ug-button-closed,
.ug-gallery-wrapper .ug-handle-tip-right.ug-skin-default.ug-button-closed{
    background-position:0px -108px;
}

.ug-gallery-wrapper .ug-handle-tip-left.ug-skin-default.ug-button-closed.ug-button-hover,
.ug-gallery-wrapper .ug-handle-tip-right.ug-skin-default.ug-button-closed.ug-button-hover{
    background-position:0px -72px;
}


/* top and bottom handle */

.ug-gallery-wrapper .ug-handle-tip-top.ug-skin-default,
.ug-gallery-wrapper .ug-handle-tip-bottom.ug-skin-default{  
    width:36px;
    height:22px;
    background-image:url('images/grid_handle_black_top.png');
    background-repeat:no-repeat;
    background-position:-36px 0px;
}

.ug-gallery-wrapper .ug-handle-tip-bottom.ug-skin-default{
    background-image:url('images/grid_handle_black_bottom.png');
    background-position:-36px 0px;
}

.ug-gallery-wrapper .ug-handle-tip-top.ug-skin-default.ug-button-hover,
.ug-gallery-wrapper .ug-handle-tip-bottom.ug-skin-default.ug-button-hover{
    background-position:0px 0px;    
}

.ug-gallery-wrapper .ug-handle-tip-top.ug-skin-default.ug-button-closed,
.ug-gallery-wrapper .ug-handle-tip-bottom.ug-skin-default.ug-button-closed{
    background-position:-108px 0px;
}

.ug-gallery-wrapper .ug-handle-tip-top.ug-skin-default.ug-button-closed.ug-button-hover,
.ug-gallery-wrapper .ug-handle-tip-bottom.ug-skin-default.ug-button-closed.ug-button-hover{
    background-position:-72px 0px;
}

我想根据时间段对标志进行求和。 我试图以两种不同方式在此期间使用sum函数:

id period avg_amt flag
111 1   123.5      1
211 1   143.1      1
311 2   122.1      1
411 3   214.5      1
511 3   124.6      0
611 3   153.2      1

select 
       id, period, avg_amt, flag, sum(flag) over (partition by id order by period)
from dataset

输出未返回我期望的值,即对于期间1 sum = 3,期间2和1,期间3和2。

您能告诉我什么地方出问题了吗?谢谢

1 个答案:

答案 0 :(得分:0)

获得简单的总和:

select period, sum(flag) total_flag
from dataset
group by period

在SQL Server中,要重新添加其余信息,可以使用子查询并将其重新加入:

select id, dataset.period, avg_amt, flag, total_flag
from dataset
inner join (
   select period, sum(flag) total_flag
   from dataset
   group by period
) TF on TF.period=dataset.period

我希望使用teradata-sql-assistant仍然可以。