【问题标题】:the right command to select the number of products of every client that had a purchase in the last month正确的命令选择每个客户在上个月购买的产品数量
【发布时间】:2016-07-19 16:25:06
【问题描述】:

oracle 问题我已经去这张表了

COM (Clientnumber,Productnumber,DateofPurchase) ; 我想知道如何使用 sysdate 比较日期和购买日期,以了解上个月发生的日期

【问题讨论】:

  • sysdate 是一个oracle 伪列,但问题标记为mysql。是哪一个?
  • 我的错,我正在研究两者并且对它的oracle感到困惑

标签: oracle


【解决方案1】:

我觉得这个可以解决你的问题

SELECT * FROM COM
WHERE DateofPurchase between trunc((trunc(sysdate,'MM')-1),'MM')  and trunc(sysdate,'MM')-1

trunc((trunc(sysdate,'MM')-1),'MM') -->  last_month_fist_day
trunc(sysdate,'MM')-1               -->  last_month_last_day

【讨论】:

    【解决方案2】:

    您可以使用 PERIOD_DIFF

    select Productnumber from COM where 
    PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM NOW()), EXTRACT(YEAR_MONTH FROM    DateofPurchase)) = 1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 2020-03-06
      • 1970-01-01
      • 2021-03-17
      • 2021-12-05
      相关资源
      最近更新 更多