×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

@

master.d_date c, 不应该有这个 ","

SELECT
b.member_id,
CASE when c.cal_dt >= to_date('2006-01-01','yyyy-mm-dd')
and c.cal_dt < to_date('2006-02-01','yyyy-mm-dd')
THEN '1'
when c.cal_dt >= to_date('2006-02-01','yyyy-mm-dd')
and c.cal_dt < to_date('2006-03-01','yyyy-mm-dd')
THEN '2'
ELSE '3'
end as flag ,
sum(a.value_amt) as total_spend
FROM
master.f_purchase_category b,
master.d_date c
WHERE b.d_trans_date_key=c.d_date_key
and c.cal_dt >= to_date ('2006-01-01','yyyy-mm-dd')
and c.cal_dt < to_date ('2006-03-20','yyyy-mm-dd')
group by a.member_id, flag
Report

Replies, comments and Discussions:

  • 工作学习 / 专业知识杂谈 / SQL 高手请帮忙!!
    Run a query on Oracle, 但有ORA-00933 error (SQL command .doesnt end properly)
    本人水平有限, 不知如何重写.
    SQL 高手请帮忙!!

    SELECT
    a.member_id,
    flag,
    sum(a.value_amt) as total_spend
    FROM
    master.f_purchase_category b,
    master.d_date c,
    WHERE b.d_trans_date_key=c.d_date_key
    and c.cal_dt >= to_date ('2006-01-01','yyyy-mm-dd')
    and c.cal_dt < to_date ('2006-03-20','yyyy-mm-dd')
    group by a.member_id,
    CASE when c.cal_dt >= to_date('2006-01-01','yyyy-mm-dd')
    and c.cal_dt < to_date('2006-02-01','yyyy-mm-dd')
    THEN '1'
    when c.cal_dt >= to_date('2006-02-01','yyyy-mm-dd')
    and c.cal_dt < to_date('2006-03-01','yyyy-mm-dd')
    THEN '2'
    ELSE '3'
    end as flag
    • 怎么没见a?
      • Should be "b". Sorry.
        • no where , having
    • master.d_date c, 不应该有这个 ","
      SELECT
      b.member_id,
      CASE when c.cal_dt >= to_date('2006-01-01','yyyy-mm-dd')
      and c.cal_dt < to_date('2006-02-01','yyyy-mm-dd')
      THEN '1'
      when c.cal_dt >= to_date('2006-02-01','yyyy-mm-dd')
      and c.cal_dt < to_date('2006-03-01','yyyy-mm-dd')
      THEN '2'
      ELSE '3'
      end as flag ,
      sum(a.value_amt) as total_spend
      FROM
      master.f_purchase_category b,
      master.d_date c
      WHERE b.d_trans_date_key=c.d_date_key
      and c.cal_dt >= to_date ('2006-01-01','yyyy-mm-dd')
      and c.cal_dt < to_date ('2006-03-20','yyyy-mm-dd')
      group by a.member_id, flag
      • 好像还是不行.
      • 没装Oracle,没法帮你试,看看这个好不好用吧...
        SELECT
        b.member_id,
        to_char(c.cal_dt,'mm'),
        sum(a.value_amt) as total_spend
        FROM
        master.f_purchase_category b,master.d_date c
        WHERE b.d_trans_date_key=c.d_date_key
        and c.cal_dt >= to_date ('2006-01-01','yyyy-mm-dd')
        and c.cal_dt < to_date ('2006-03-20','yyyy-mm-dd')
        group by b.member_id, to_char(c.cal_dt,'mm')
    • remove "as flag" from the end should work
    • Solved. THanks for your help.
      • 怎么解决的也不说说?