oracle查询增加日期条件
selectcasewhenqj_dept.isdls='Y'thenqj_dept.deptcodeelsedeptup.deptcodeend代理商编码,casewh...
select case when qj_dept.isdls= 'Y' then qj_dept.deptcode else deptup.deptcode end 代理商编码,
case when qj_dept.isdls= 'Y' then qj_dept.deptname else deptup.deptname end 代理商名称,case when qj_dept.isdls= 'Y' then '' else qj_dept.deptcode end 门店编码,
case when qj_dept.isdls= 'Y' then '' else qj_dept.deptname end 门店名称,nvl(sale.allsale,0) 零售金额,-nvl(dh.alldh,0) 订货金额,nvl(kc.allkc,0) 现库存
from qj_dept
left join (select pk_dept,-sum(nvl(ddef2,0)) allsale from qj_dept_ck where strdef1 like ('%门店销售%') group by pk_dept) sale
on sale.pk_dept=qj_dept.pk_dept
left join (select pk_dept,deptcode,deptname from qj_dept) deptup
on deptup.pk_dept=qj_dept.pk_dept_up
left join (select pk_dept,-sum(nvl(ddef2,0)) alldh from qj_dept_ck where strdef1 like ('%代理商到门店入库库%') group by pk_dept) dh
on dh.pk_dept=qj_dept.pk_dept
left join (select pk_dept,sum(nvl(ddef2,0)) allkc from qj_dept_ck group by pk_dept) kc
on kc.pk_dept=qj_dept.pk_dept
以上是查询条件,现在我想增加一个月份条件和一个省份字段,该如何增加呢?月份格式为2015-02
select
…………………………
case when qj_dept.isdls= 'Y' then qj_dept.deptname else deptup.deptname end 代理商名称,
case when qj_dept.isdls= 'Y' then '' else qj_dept.strdef1 end 省份,
case when qj_dept.isdls= 'Y' then '' else qj_dept.deptcode end 门店编码,
…………………………
where strdef1 like ('%门店销售%' )and (qj_dept_ck.czdate like '2014-11%' )
省份已经取到值了,最后一行是增加的日期筛选,但是保存的时候提示
SQL语法有误——ORA-00904: "QJ_DEPT_CK"."CZDATE": 标识符无效 展开
case when qj_dept.isdls= 'Y' then qj_dept.deptname else deptup.deptname end 代理商名称,case when qj_dept.isdls= 'Y' then '' else qj_dept.deptcode end 门店编码,
case when qj_dept.isdls= 'Y' then '' else qj_dept.deptname end 门店名称,nvl(sale.allsale,0) 零售金额,-nvl(dh.alldh,0) 订货金额,nvl(kc.allkc,0) 现库存
from qj_dept
left join (select pk_dept,-sum(nvl(ddef2,0)) allsale from qj_dept_ck where strdef1 like ('%门店销售%') group by pk_dept) sale
on sale.pk_dept=qj_dept.pk_dept
left join (select pk_dept,deptcode,deptname from qj_dept) deptup
on deptup.pk_dept=qj_dept.pk_dept_up
left join (select pk_dept,-sum(nvl(ddef2,0)) alldh from qj_dept_ck where strdef1 like ('%代理商到门店入库库%') group by pk_dept) dh
on dh.pk_dept=qj_dept.pk_dept
left join (select pk_dept,sum(nvl(ddef2,0)) allkc from qj_dept_ck group by pk_dept) kc
on kc.pk_dept=qj_dept.pk_dept
以上是查询条件,现在我想增加一个月份条件和一个省份字段,该如何增加呢?月份格式为2015-02
select
…………………………
case when qj_dept.isdls= 'Y' then qj_dept.deptname else deptup.deptname end 代理商名称,
case when qj_dept.isdls= 'Y' then '' else qj_dept.strdef1 end 省份,
case when qj_dept.isdls= 'Y' then '' else qj_dept.deptcode end 门店编码,
…………………………
where strdef1 like ('%门店销售%' )and (qj_dept_ck.czdate like '2014-11%' )
省份已经取到值了,最后一行是增加的日期筛选,但是保存的时候提示
SQL语法有误——ORA-00904: "QJ_DEPT_CK"."CZDATE": 标识符无效 展开
2个回答
展开全部
省份字段可以加到from之前,月份条件的话,假设条件是qj_dept表的字段条件,那SQL可以如下写法(注意新增的“,shengfen 省份”以及“where yuefen > to_date('2015-02','yyyy-mm')”):
select case when qj_dept.isdls= 'Y' then qj_dept.deptcode else deptup.deptcode end 代理商编码,
case when qj_dept.isdls= 'Y' then qj_dept.deptname else deptup.deptname end 代理商名称,case when qj_dept.isdls= 'Y' then '' else qj_dept.deptcode end 门店编码,
case when qj_dept.isdls= 'Y' then '' else qj_dept.deptname end 门店名称,nvl(sale.allsale,0) 零售金额,-nvl(dh.alldh,0) 订货金额,nvl(kc.allkc,0) 现库存,shengfen 省份
from qj_dept
where yuefen > to_date('2015-02','yyyy-mm')
left join (select pk_dept,-sum(nvl(ddef2,0)) allsale from qj_dept_ck where strdef1 like ('%门店销售%') group by pk_dept) sale
on sale.pk_dept=qj_dept.pk_dept
left join (select pk_dept,deptcode,deptname from qj_dept) deptup
on deptup.pk_dept=qj_dept.pk_dept_up
left join (select pk_dept,-sum(nvl(ddef2,0)) alldh from qj_dept_ck where strdef1 like ('%代理商到门店入库库%') group by pk_dept) dh
on dh.pk_dept=qj_dept.pk_dept
left join (select pk_dept,sum(nvl(ddef2,0)) allkc from qj_dept_ck group by pk_dept) kc
on kc.pk_dept=qj_dept.pk_dept
select case when qj_dept.isdls= 'Y' then qj_dept.deptcode else deptup.deptcode end 代理商编码,
case when qj_dept.isdls= 'Y' then qj_dept.deptname else deptup.deptname end 代理商名称,case when qj_dept.isdls= 'Y' then '' else qj_dept.deptcode end 门店编码,
case when qj_dept.isdls= 'Y' then '' else qj_dept.deptname end 门店名称,nvl(sale.allsale,0) 零售金额,-nvl(dh.alldh,0) 订货金额,nvl(kc.allkc,0) 现库存,shengfen 省份
from qj_dept
where yuefen > to_date('2015-02','yyyy-mm')
left join (select pk_dept,-sum(nvl(ddef2,0)) allsale from qj_dept_ck where strdef1 like ('%门店销售%') group by pk_dept) sale
on sale.pk_dept=qj_dept.pk_dept
left join (select pk_dept,deptcode,deptname from qj_dept) deptup
on deptup.pk_dept=qj_dept.pk_dept_up
left join (select pk_dept,-sum(nvl(ddef2,0)) alldh from qj_dept_ck where strdef1 like ('%代理商到门店入库库%') group by pk_dept) dh
on dh.pk_dept=qj_dept.pk_dept
left join (select pk_dept,sum(nvl(ddef2,0)) allkc from qj_dept_ck group by pk_dept) kc
on kc.pk_dept=qj_dept.pk_dept
追问
不好意思!我是刚接触数据库。
我们的数据库是oracle,语法与SQL通用吗?
还有就是我需要获得的是2月的销售记录,那是不是应该是大于或等于2015-02,小于或等于2015-03
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询