表1 (产品表,id,产品编号,产品名称)
 Id  Product  Name
 1    101       fff
 2    201       bbb表2(价格表,id,产品Id,起始日期,结束日期,价格)
 Id   ProductId  startDate   endDate   Price
  1    101        2007-1-1  2007-9-1   500
  2    101        2007-9-1  2007-10-1  400
  3    201        2007-1-1  2007-9-1   1500
  4    201        2007-9-1  2007-10-1  1400表2,是根据季节来定价的,在9月1至10月1日期间,进行降价促销,那么,要查询产品101在7月至10月间的价格情况,查询语句怎么写?附:查询结果 如下:
  ProductId  startDate   endDate   Price
   101        2007-7-1  2007-9-1   500
   101        2007-9-1  2007-10-1  400谢谢!

解决方案 »

  1.   

    select a.product,decode(sign(startdate-to_date('20070701','yyyymmdd')),1,startdate,0,startdate,-1,(to_date('20070701','yyyymmdd')) startdate,b.endDate ,b. Price
    from a,b
    where a.product=b.product and a.product='101'
      

  2.   

    to hebo2005():
    谢谢。后面的to_date('20070701','yyyymmdd')的时间是不是'20071001'?
      

  3.   

    decode(sign(startdate-to_date('20070701','yyyymmdd')),1,startdate,0,startdate,-1,(to_date('20070701','yyyymmdd')) 
    这句话的意思就是如果是大于或者等于7.1号的就显示当前的STARTDATE
    如果小于7.1号的,就显示7.1
    不知道你问的
    后面的to_date('20070701','yyyymmdd')的时间是不是'20071001'?
    是什么意思