select city,count(*),count(decode(flog,0,null,flog)) from tbname
搂主找本书之类的看看sql基础吧 这个用group by就可以了。
SELECT city,count(*) COUNT,sum(to_number(flog)) FLOG-COUNT FROM t1 GROUP BY city;
select city,count(*),count(decode(flog,0,null,flog,1)) from tbname group by city
不好意思,漏了group by city
不好意思,我的FLOG标志位现在是用的T和F 也就是说:table是如下形式: CITY FLOG 北京 T 北京 T 北京 F 上海 T 上海 T 上海 T 上海 T 上海 T 上海 F 上海 F我想生成一个统计用的查询,查询结果要如下: CITY COUNT FLOG-COUNT 北京 3 2 上海 7 5也就是说按城市名称汇总,count字段填写的内容是总共有多少记录数,FLOG-COUNT填写的是flog为T的记录数; 大哥,救救我吧,我先谢谢了;
稍改一下就行了。建议楼主还是先看看基础资料吧。select city,count(*),count(decode(flog,'F',null,flog,1)) from tbname group by city或: select city,count(*),sum(decode(flog,'T',1,0)) from tbname group by city
SQL> select city,count(*),sum(decode(flag,'F',0,'T',1)) 2 flag_count from city_test 3 group by city 4 /CITY COUNT(*) FLAG_COUNT ------------------------------------ ---------- --------- 上海 5 3北京 3 2SQL>
select city,count(*),sum(to_number(flog)) from t1 group by city;
select city,count(city),count(decode(flog,0,null,flog)) from tbname group by city
如果是用T和F就改为: select city,count(city),count(decode(flog,F,null,flog)) from tbname group by city
select city,count(city),count(decode(flog,'F',null,flog)) from tbname group by city
select city,count(*) as count,sum(decode(flog,'T',1,0)) as flog_count from tablename group by city
这样可以吧 select city,count(*),sum(decode(flog,1,1,0)) from tbname group by city
select city CITY,count(*) COUNT,sum(decode(flog,'T',1,0)) FLOG-COUNT from tbname group by city
select CITY,count(*) COUNT,sum(flog) FLOG-COUNT from tbname group by city
COUNT 就是记录的条数 FLOG-COUNT 就是一个累计 select nvl(sum(city),0) city from …… 这样就可以了
这个用group by就可以了。
FROM t1
GROUP BY city;
也就是说:table是如下形式:
CITY FLOG
北京 T
北京 T
北京 F
上海 T
上海 T
上海 T
上海 T
上海 T
上海 F
上海 F我想生成一个统计用的查询,查询结果要如下:
CITY COUNT FLOG-COUNT
北京 3 2
上海 7 5也就是说按城市名称汇总,count字段填写的内容是总共有多少记录数,FLOG-COUNT填写的是flog为T的记录数;
大哥,救救我吧,我先谢谢了;
from tbname
group by city或:
select city,count(*),sum(decode(flog,'T',1,0))
from tbname
group by city
2 flag_count from city_test
3 group by city
4 /CITY COUNT(*) FLAG_COUNT
------------------------------------ ---------- ---------
上海 5 3北京 3 2SQL>
select city,count(city),count(decode(flog,F,null,flog)) from tbname group by city
select city,count(*),sum(decode(flog,1,1,0)) from tbname group by city
FLOG-COUNT
就是一个累计
select nvl(sum(city),0) city from ……
这样就可以了