dongyue6199 2014-04-18 04:57
浏览 10
已采纳

MYSQL月份()查询的地点或HAVING

I'm trying to create a report that shows data for the selected month. My MySQL query looks like this:

SELECT Count(images.image_url)             AS num_images, 
       ( Day(Date(timestamp)) )            AS tday, 
       Month(Date(transactions.timestamp)) AS month, 
       transactions.sr_no 
FROM   bni_pixcapp_client_details AS transactions 
       INNER JOIN bni_pixcapp_image_urls AS images 
               ON images.sr_no = transactions.sr_no 
WHERE  Month(Date(transactions.timestamp)) = 4 
       AND Year(Date(transactions.timestamp)) = 2014 
       AND transactions.payment_status = 'Manually created' 
        OR payment_status = 'Completed' 
GROUP  BY Day(Date(timestamp)) 

Query looks fine right?

But then here are the results

But here are the results

How do I get rid of the extraneous entry for March? I tried using HAVING instead of WHERE but couldn't get the query to run.

  • 写回答

2条回答 默认 最新

  • douguai7291 2014-04-18 05:07
    关注

    Try this, I think your Or condition should be in ().

    SELECT Count(images.image_url)             AS num_images, 
           ( Day(Date(timestamp)) )            AS tday, 
           Month(Date(transactions.timestamp)) AS month, 
           transactions.sr_no 
    FROM   bni_pixcapp_client_details AS transactions 
           INNER JOIN bni_pixcapp_image_urls AS images 
                   ON images.sr_no = transactions.sr_no 
    WHERE  Month(Date(transactions.timestamp)) = 4 
           AND Year(Date(transactions.timestamp)) = 2014 
           AND (
                 transactions.payment_status = 'Manually created' 
               OR 
                 payment_status = 'Completed' 
               )
    GROUP  BY Day(Date(timestamp)) 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?