有一个表包括产品名和零售价两个列,要求写一条SQL,同时输出
零售价在:
101元~200元的产品数量,
201~300元的产品数量,
301~400元的产品数量多谢!~~
零售价在:
101元~200元的产品数量,
201~300元的产品数量,
301~400元的产品数量多谢!~~
解决方案 »
- 小弟无能,跪求各路大虾支招(PL/SQL连接ORACLE问题)
- 新人求教oracle学习路线
- Orcle的查询语句优化.
- 关于一个SQL语句的写法
- 如何循环动态sql的结果集并拼接字段的值为字符串,这个sql中union了好几个表
- 在进行多个表连接时,FROM中的表的顺序要按照记录数由多到少的顺序来排列,这么做的原因是什么呢?
- 从oracle中向sql中导数据,用语句来实现如何办?
- 求一个SQL语句!(共同提高)
- 我写了一个存储过程用于更改数据库用户密码,但只有该数据库主用户能成功执行。祥见内容
- 在线等待---服务器端与client端可以装在同一台机器上吗?
- 急问:这条语句的作用,谢谢大虾们~~
- 关于ORACLE的utl_file包的资料
sum(case when price>=201 and price<=300 then 1 else 0 end) as '201元~300元',
sum(case when price>=301 and price<=400 then 1 else 0 end) as '301元~400元'
from tablename
group by price;
不过还有问题price 可以直接是列名吗??还是要事先声明:DECLARE
price tablename.年龄%TYPE;
……
所以根據樓主的意思,去掉你那個分組條件就OK了:
select sum(case when price>=101 and price<=200 then 1 else 0 end) as '101元~200元',
sum(case when price>=201 and price<=300 then 1 else 0 end) as '201元~300元',
sum(case when price>=301 and price<=400 then 1 else 0 end) as '301元~400元'
from tablename;
select nvl(sum(case when price>=101 and price<=200 then 1 else 0 end),0) as '101元~200元',
nvl(sum(case when price>=201 and price<=300 then 1 else 0 end),0) as '201元~300元',
nvl(sum(case when price>=301 and price<=400 then 1 else 0 end),0) as '301元~400元'
from tablename;