易截截图软件、单文件、免安装、纯绿色、仅160KB

oracle分组查询

dpart  uname    usex
A a1 1
A a2 1
A a3 0
A a4 0
A a5 1
B b1 0
B b2 1

希望实现
  dpart  sex1  sex0  sum
    A      3      2    5
    B      1      1    2

求sql语句
select dpart, sum(case when usex=1 then 1 end) sex1, sum(case when usex=0 then 1 end) sex0, count(usex) sum from t group by dpart;

select dpart,
  count(decode(usex,1,1))sex1,
  count(decode(usex,0,1))sex0,
  count(1)sum
from tt
group by dpart


相关问答:

php 中查询oracle date 类型数据的问题?

日前用oci函数查询oracle数据时出现个问题,就是在查询到date类型的数据时,使用pl/sql 查询oracle库中的数据显示是
2009-9-29 12:12:12
但是通过语句select * from tablename 查询,使用oci_fetch_array() ......

PHP 连接Oracle 出错

<?php
  getenv("ORACLE_HOME");
  $conn=ocilogon("test","test","test_db");
  if($conn)  
  echo success;  
&nb ......

Oracle 启动的问题

oracle not available
shared memory realm does not exist
请问高手这个问题如何解决?
http://www.inthirties.com/thread-109-2-1.html

指定下ORACLE_SID,ORACLE_HOME看看,不行就用1楼得方法了..

cm ......

Oracle如何使用窗口函数实现这样的查询

表记录
======================================
name        date        score
Fei Zhang  1          100
Fei Zhang  ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号