‘壹’ oracle sql 用select count() from 表 用法
select count(市),市 from 表 group by 市
这样取出来的就是市和市的人数,有几个市就有几条数据
‘贰’ oracle sql怎样统计数量
可以通过district来取出字段,之后通过count计算总数量。
sql:select count(district id) from tablename;
如果id字段没有空值的话,可以通过count统计字段的总数量(字段内容可能重复)。
sql:select count(id) from tablename;
‘叁’ oracle统计查询 sql语句应该怎么写
select
substrb(create_time,1,4)
"年份",
sum(decode(substrb(create_time,6,2),'01',commission,0))
"1月",
sum(decode(substrb(create_time,6,2),'02',commission,0))
"2月",
sum(decode(substrb(create_time,6,2),'03',commission,0))
"3月",
sum(decode(substrb(create_time,6,2),'04',commission,0))
"4月",
sum(decode(substrb(create_time,6,2),'05',commission,0))
"5月",
sum(decode(substrb(create_time,6,2),'06',commission,0))
"6月",
sum(decode(substrb(create_time,6,2),'07',commission,0))
"7月",
sum(decode(substrb(create_time,6,2),'08',commission,0))
"8月",
sum(decode(substrb(create_time,6,2),'09',commission,0))
"9月",
sum(decode(substrb(create_time,6,2),'10',commission,0))
"10月",
sum(decode(substrb(create_time,6,2),'11',commission,0))
"11月",
sum(decode(substrb(create_time,6,2),'12',commission,0))
"12月"
from
test
group
by
substrb(create_time,1,4)
此语句是按create_time字段是字符型给出的,如果你的表中此字段是日期型,则进行一下转化
‘肆’ oracle函数 动态sql 给count变量赋值
虽然你没问问题,但是我想你大概的意思是动态语句的值怎么获取吧。
动态语句里不能写into,得放到外面来。这么写:
executeimmediatep_sqlintop_max;
‘伍’ oracle 如何实现sql循环计数显示
可用count函数来计算某个字段重复次数。
如test表中数据如下:
现在要查询name列中,各个名字重复的次数,可用如下语句:
搜索
select name,count(*) from test group by name;
查询结果:
‘陆’ oracle,sql语句同一表中同一字段不同条件count(*)
典型的case when 语句块可以解决.先映射表的视图,添加条件过滤
例如性别为M的和为F的分别计数name,可以写成:
select b1.sex, count(b1.name)
from ((select bh.*,
(case when sex= 'M' then 1 else 0 end) as qty /*此处可写多个when*/
from user_d bh) b1)
group by b1.sex
‘柒’ oracle sql中count、case函数运用
count
表示的是计数,也就是说记录的条数,通常和分组函数一起使用。
sql:select
userId
,
count(*)
from
tablename
group
by
userId。
case表示的是多条件判断。
sql:select
ename,
case
when
sal<1000
then
'lower'
when
sal>1001
and
sal<2000
then
'modest'
when
sal>2001
and
sal<4000
then
'high'
else
'too
high'
end
from
emp;
以上语句就是一个简单的判断工资等级的一个case用法。