需求统计表中相同地区(区号)的数量,并倒序排序.
例子
表tab:id tele
1 010-11111111
2 0532-1515151
3 0532-1510000
4 0532-2333333
5 010-16666666
要求得到结果
quhao count
0532 3
010 2
我试着这样写,可是总是出错.
select tele(0,4) count(id) as count from tab group by tele(0,4)
请高手指点,我该怎样才能更好的得到我要的结果
例子
表tab:id tele
1 010-11111111
2 0532-1515151
3 0532-1510000
4 0532-2333333
5 010-16666666
要求得到结果
quhao count
0532 3
010 2
我试着这样写,可是总是出错.
select tele(0,4) count(id) as count from tab group by tele(0,4)
请高手指点,我该怎样才能更好的得到我要的结果
解决方案 »
- 传入表名,字段名,条件,返回结果集的function或者proc
- 求各位高人指点
- 问一个问题:V$tablespace和dba_tablespaces,都是表示表空间信息的。为什么不放在一个表中呢?
- 数据不多,但速度奇慢,有什么问题了,看我的PL/SQL
- 关于用 count(*)的方法取得表中的记录总条数的方法
- CONNECT BY 超难问题!在线等....高手请进!
- 怎么把这个带BETWEEN 的日期查询条件转换成数字比较
- 新手!!!!!!!!!!!!!
- 如何把字段1中身份证号码(字符类型)中的出生年月提取出来并转为日期类型放到字段2中?
- ORA-24337:语句未准备好。这个错误该怎么解决啊?急,在线等。
- 还算简单的问题---要求使用自表关联和exists两种方法实现
- 表table建了一个CLOB字段,请问如何插入长字符串呢,,老提示"字符串文字太长"
insert into temp111 values('010-11111111');
insert into temp111 values('0532-1515151');
insert into temp111 values('0532-1510000');
insert into temp111 values('0532-2333333');
insert into temp111 values('010-16666666');create table temp222 (quhao varchar2(100));
insert into temp222 values('010');
insert into temp222 values('0532');
select t2.quhao,count(t2.quhao) m_count from temp111 t1 inner join temp222 t2 on substr(t1.tele,1,length(t2.quhao))=t2.quhao
group by t2.quhao
group by t2.quhao
order by t2.quhao desc;
这样就OK了,count
select substr(tele,0,4) as tel,count(*) as count
from tab group by substr(tele,0,4) order by count desc
1 010-11111111
2 0532-1515151
取出的东西不一样啊,对于0532是但是010就不是了
select t2.quhao,count(t2.quhao) m_count from temp111 t1 inner join temp222 t2 on substr(tele,0,instr(tele,'-',1)-1)=t2.quhao
group by t2.quhao
order by t2.quhao desc;