有个Access 的sql语句不正确不知道问题出在哪里了,请路过的大侠们帮帮忙啊???????????????SELECT t.t_name, sum(ipd.ipd_money) AS totalMoney, t.t_type
FROM incomePayout AS ip, incomePayoutDetail AS ipd, types AS t
WHERE ip.ip_id=ipd.ip_id And ipd.t_id=t.t_id
GROUP BY t.t_name, t.t_type
HAVING DATEDIFF(month,ip.ip_date,now());

解决方案 »

  1.   

    SELECT  sum(ipd.ipd_money) AS totalMoney FROM ....
    也许只能这样吧...
      

  2.   

    前面的都没错,添上having子句就有错了
      

  3.   

    having后面是一个条件
    SELECT t.t_name, sum(ipd.ipd_money) AS totalMoney, t.t_type 
    FROM incomePayout AS ip, incomePayoutDetail AS ipd, types AS t 
    WHERE ip.ip_id=ipd.ip_id And ipd.t_id=t.t_id 
    GROUP BY t.t_name, t.t_type HAVING DATEDIFF(month,ip.ip_date,now())='0';试试
      

  4.   

    DateDiff在Access与Sql server中的差别
    差别在于interval是否要用引号;Access:
    DateDiff('n',lastActiveTime,'" + DateTime.Now + "')>=5Sql:
    server:DateDiff(n,lastActiveTime,'" + DateTime.Now + "')>=5interval 参数 (参数:为操作、事件、方法、属性、函数或过程提供信息的值。)包含以下设置:设置 说明 
    yyyy 年 
    q 季度 
    m 月 
    y 某年的某一天 
    d 天 
    w 工作日 
    ww 周 
    h 时 
    n 分 
    s 秒  
    参数  
    Year 
    yyyy Quarter 
    q Month 
    m Day of year 
    y Day 
    d Weekday 
    w Week 
    ww Hour 
    h Minute 
    n Second 
      

  5.   

    按4楼的说法,弄了,报错:试图执行的查询中不包含作为合计函数一部分的特定表达式
    'HAVING DATEDIFF(month,ip.ip_date,now())='0'',是怎么回事啊?
      

  6.   

    http://www.cnblogs.com/hcmfys/archive/2008/10/20/1292701.html
    看看这个资料对你有没有帮助!
      

  7.   

    我想得到当月的记录,having应该怎么写?按4楼的写法报:
    试图执行的查询中不包含作为合计函数一部分的特定表达式 
    'HAVING DATEDIFF(month,ip.ip_date,now())='0'',
    应该怎么改啊,有诚意者写下邮箱,我把数据库发过去,
    帮忙想想,应该怎么写???
      

  8.   

    问题解决了,分享一下:
    SELECT t.t_name, sum(ipd.ipd_money) AS totalMoney, t.t_type
    FROM incomePayout AS ip, incomePayoutDetail AS ipd, types AS t
    WHERE ip.ip_id=ipd.ip_id And ipd.t_id=t.t_id And DATEDIFF('m',ip.ip_date,now())=0
    GROUP BY t.t_name, t.t_type;谢谢各位顶贴!