Oracle 11G中的Cross Tab PIVOT查询

时间:2017-12-20 16:04:32

标签: sql oracle group-by pivot

我有一张表格如下

if (this.props.render && this.currentUser()) {
  return(
    <Route
      {...rest}
      render={this.props.render}
    />
} else {
    return (
       <Route
         {...rest}
         render={props => this.currentUser() ?
            <Component currentUser={this.currentUser} {...props} /> : 
            <Redirect
                to={{
                  pathname: '/auth/login',
                  state: { from: props.location }
                }}
             />
          }
        />
      )
}

我需要的是

CODE        PH_NUMBER     SUM(S.DURATION)   MIN(T.START_TIME)   CAMPAIGN
35039663    9250993319    120               19-Dec-17            297
35039725    917050139125  50                19-Dec-17            68
35039725    917050139125  370               19-Dec-17            297
35039726    919470833038  3370              19-Dec-17            68
35039726    919470833038  390               19-Dec-17            297

如何在Oracle 11G中实现这一目标?感谢

1 个答案:

答案 0 :(得分:0)

您可以通过ssl $ python2 -c 'import ssl; print ssl.OPENSSL_VERSION;' OpenSSL 1.0.2m 2 Nov 2017 (不需要使用sum子句)来轻松使用此功能:

decode

顺便说一句,在pivot表达式中使用列select code, ph_number, sum(duration) "Total Duration", min(to_char(start_time,'dd-Mon-yy')) "Min Start Time", sum(decode(campaign,297,1,0)) "297_count", sum(decode(campaign,68,1,0)) "68_count" from mytable group by code, ph_number order by code; 没有问题,因为它的值会针对单个ph_number列重复。

D e m o