恳请高手指出这sql语句的问题

hhpyt 2010-09-30 10:23:33
select x.spmc 商品名称,x.spgg 商品规格,x.spdj 商品单价,x.xsyxm 销售员姓名,j.jhcj 进货厂家,x.xsrq 销售日期,x.xssl 销售数量,x.spdj*x.xssl 销售金额
from view_spxs x left jion view_spjh j on x.spmc=j.spmc
where (x.xsrq between '20100720'and'20100819')
and
x.spmc in ('a','b','c','e','f','g')


我想把两个视图view_spxx和view_spjh分别别名为x和j,然后取x视图的spmc、spgg、spdj、xsyxm、xxrq、xxsl及j视图的jhcj字段,并将这些字段分别改别名,查询商品‘a、b、c、d、e、f、g'在20100720到20100819之间的销售情况,该语句无法执行,恳请高手指教,谢谢!!!
...全文
192 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhpyt 2010-10-01
  • 打赏
  • 举报
回复
感谢各位指点,近日内我会尽快把报错的具体提示发出来
lg200015017 2010-10-01
  • 打赏
  • 举报
回复
报错发出来再说吧。
taikongxinke 2010-10-01
  • 打赏
  • 举报
回复
日期问题,x.xsrq >=to_date('20100720','yyyymmdd') and x.xsrq <=to_date('20100819','yyyymmdd')
fwx515354 2010-10-01
  • 打赏
  • 举报
回复
你的数据库如果是在Linux下的,要考虑考虑下中文的问题。或中文加上双引号
sinpoal 2010-09-30
  • 打赏
  • 举报
回复
[Quote=引用楼主 hh371011618 的回复:]
select x.spmc 商品名称,x.spgg 商品规格,x.spdj 商品单价,x.xsyxm 销售员姓名,j.jhcj 进货厂家,x.xsrq 销售日期,x.xssl 销售数量,x.spdj*x.xssl 销售金额
from view_spxs x left jion view_spjh j on x.spmc=j.spmc
where (x.xsrq between '20100……
[/Quote]



select x.spmc 商品名称,x.spgg 商品规格,x.spdj 商品单价,x.xsyxm 销售员姓名,j.jhcj 进货厂家,x.xsrq 销售日期,x.xssl 销售数量,x.spdj*x.xssl 销售金额
from view_spxs x , view_spjh j where x.spmc=j.spmc
and (x.xsrq between to_date('20100720','yyyymmdd')and to_date('20100819','yyyymmdd'))
and x.spmc in ('a','b','c','e','f','g');
minitoy 2010-09-30
  • 打赏
  • 举报
回复
貌似没什么大问题.
hhpyt 2010-09-30
  • 打赏
  • 举报
回复
and 前后有空格,具体提示我忘了,我们开始放假了,过几天我去单位再看一下,不过很感谢这位朋友,继续期待中
心中的彩虹 2010-09-30
  • 打赏
  • 举报
回复
[Quote=引用楼主 hh371011618 的回复:]
select x.spmc 商品名称,x.spgg 商品规格,x.spdj 商品单价,x.xsyxm 销售员姓名,j.jhcj 进货厂家,x.xsrq 销售日期,x.xssl 销售数量,x.spdj*x.xssl 销售金额
from view_spxs x left jion view_spjh j on x.spmc=j.spmc
where (x.xsrq between '20100……
[/Quote]

(x.xsrq between '20100720' and '20100819')

--x.xsrq 什么类型的 是日期的话 要
x.xsrq between to_date('20100720','yyyymmdd') and to_date('20100819','yyyymmdd')
gelyon 2010-09-30
  • 打赏
  • 举报
回复

select x.spmc 商品名称,x.spgg 商品规格,x.spdj 商品单价,x.xsyxm 销售员姓名,j.jhcj 进货厂家,
x.xsrq 销售日期,x.xssl 销售数量,x.spdj*x.xssl 销售金额
from view_spxs x , view_spjh j
where x.spmc=j.spmc
AND x.xsrq between '20100720'and'20100819'
AND x.spmc in ('a','b','c','e','f','g');
caofaping 2010-09-30
  • 打赏
  • 举报
回复
你用左连接可以取view_spjh 的值嘛?
改成等值连接应该就可以了

select x.spmc 商品名称,
x.spgg 商品规格,
x.spdj 商品单价,
x.xsyxm 销售员姓名,
j.jhcj 进货厂家,
x.xsrq 销售日期,
x.xssl 销售数量,
x.spdj * x.xssl 销售金额
from view_spxs x
, view_spjh j
where (x.xsrq between '20100720' and '20100819')
and x.spmc in ('a', 'b', 'c', 'e', 'f', 'g')
and x.spmc = j.spmc
da21 2010-09-30
  • 打赏
  • 举报
回复
'20100720'and'20100819'
and 前后加空格 ??
da21 2010-09-30
  • 打赏
  • 举报
回复
有什么出错提示?
tlxing 2010-09-30
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wkc168 的回复:]
引用楼主 hh371011618 的回复:
(x.xsrq between '20100720' and '20100819')

--x.xsrq 什么类型的 是日期的话 要
x.xsrq between to_date('20100720','yyyymmdd') and to_date('20100819','yyyymmdd')[/Quote]
日期不对
js_flybird 2010-09-30
  • 打赏
  • 举报
回复
where (x.xsrq between '20100720'and'20100819')改成
where (x.xsrq between to_date('20100720','yyyymmdd') and to_date('20100819','yyyymmdd'))
hhpyt 2010-09-30
  • 打赏
  • 举报
回复
回复10楼,jion 是我打错了,在实际中是正确的
js_flybird 2010-09-30
  • 打赏
  • 举报
回复
left jion中的jion应改成join
ys332617184 2010-09-30
  • 打赏
  • 举报
回复
我也估计是日期出的问题

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧