avatar
One sql question help!# Database - 数据库
h*u
1
If I have a table named Emp and it has a column, named hire_time.
how to write a query to get the result like:
total | 1995 | 1996|
20 3 4
in one record?
avatar
b*e
2
in my opinion, no way.
if you use 'group by', you can't get the number for each year,
but you can't get total number.

【在 h**u 的大作中提到】
: If I have a table named Emp and it has a column, named hire_time.
: how to write a query to get the result like:
: total | 1995 | 1996|
: 20 3 4
: in one record?

avatar
z*y
3

How about this :
Select count(*) as year_number, year
from table
group by year
where year is not null
But by this way, still cannot put the total of totall at the same line.

【在 b*e 的大作中提到】
: in my opinion, no way.
: if you use 'group by', you can't get the number for each year,
: but you can't get total number.

avatar
n*a
4
If you are using Oracle 8.1.6 upper, you are lucky, because you can do this:
select year, count(*) as year_number
from table
where year is not null
group by rollup(year)

【在 z***y 的大作中提到】
:
: How about this :
: Select count(*) as year_number, year
: from table
: group by year
: where year is not null
: But by this way, still cannot put the total of totall at the same line.

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