avatar
x*g
1
I have data as follows:
A b c
A d c
A h d
B a c
C a d
B a a
A b b
I want to return something like this:
A b c
d c
h d
b b
subtotal 4
B a c
a a
subtotal 2
C a d
subtotal 1
total 7
I tried rollup and cube but can't get it work,
can anyone help? Thanks.
avatar
c*t
2
did you try group by and count?

【在 x*g 的大作中提到】
: I have data as follows:
: A b c
: A d c
: A h d
: B a c
: C a d
: B a a
: A b b
: I want to return something like this:
: A b c

avatar
x*g
3
yes I tried, but I can't get the output I want...

【在 c*****t 的大作中提到】
: did you try group by and count?
avatar
B*g
4
SELECT col1, col2, col3, COUNT(1)
FROM tab1
GROUP BY ROLLUP(col1, (col2,col3))

【在 x*g 的大作中提到】
: yes I tried, but I can't get the output I want...
avatar
x*g
5
is this for oracle server?
it doesn't work in sql server.
thanks.

【在 B*****g 的大作中提到】
: SELECT col1, col2, col3, COUNT(1)
: FROM tab1
: GROUP BY ROLLUP(col1, (col2,col3))

avatar
B*g
6
oracle

【在 x*g 的大作中提到】
: is this for oracle server?
: it doesn't work in sql server.
: thanks.

avatar
f*e
7
You need to write a SQL function to print out exactly what you mentioned in
your first post.

【在 x*g 的大作中提到】
: yes I tried, but I can't get the output I want...
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。