查询不正确

时间:2013-01-07 06:41:45

标签: java mysql phpmyadmin

我有以下两个查询都是相同的但只在结构上有所不同。

首先查询:

SELECT DISTINCT 
    u.username, r.value, u.amount AS `amount`
FROM 
    Daily_Balance_Updates u
INNER JOIN 
    Role r ON u.role_id = r.id
WHERE 
    u.updated_at = (SELECT MAX(inner_u.updated_at)
                    FROM Daily_Balance_Updates AS inner_u
                    WHERE inner_u.username = u.username
                       && amount > 0
                       && UNIX_TIMESTAMP( inner_u.updated_at ) < UNIX_TIMESTAMP( '2013-1-3 23:59:59' )
)
ORDER BY 
    r.value, UNIX_TIMESTAMP( u.updated_at ) DESC

Phpmyadmin

中正常工作

第二次查询

我在Java中使用时的相同查询我声明如下:

query="SELECT DISTINCT u.username, r.value, u.amount AS `amount' FROM Daily_Balance_Updates     u INNER JOIN Role r ON u.role_id = r.id WHERE u.updated_at = ("
+ "SELECT MAX(inner_u.updated_at) FROM Daily_Balance_Updates AS inner_u WHERE inner_u.username = u.username && amount > 0 && UNIX_TIMESTAMP( inner_u.updated_at ) < UNIX_TIMESTAMP('" +date+" 23:59:59' )) ORDER BY r.value DESC,UNIX_TIMESTAMP( u.updated_at )"

但是当我执行它时,它会在 phpmyadmin java

中出错

错误

  

字段列表中的未知表'u'

我的日志:

12:23:17,963 INFO  [STDOUT] 2013-01-07 12:23:17,962 ERROR 
    com.walletplus.report.dao.ReportDaoMysql -  Thread #98  - 
    StatementCallback; bad SQL grammar 
        [SELECT DISTINCT u.username, r.value, u.amount AS `amount' FROM 
            Daily_Balance_Updates u INNER JOIN Role r ON u.role_id = r.id   
            WHERE u.updated_at = (SELECT MAX(inner_u.updated_at) FROM
            Daily_Balance_Updates AS inner_u WHERE inner_u.username = u.username    
            && amount > 0 && UNIX_TIMESTAMP( inner_u.updated_at ) < 
            UNIX_TIMESTAMP('2013-01-01 23:59:59' )) ORDER BY r.value DESC]; 
            nested exception is java.sql.SQLException: Unknown table 'u' in field list

问题:

查询有什么问题?好像没事。

1 个答案:

答案 0 :(得分:0)

SQL:  `amount` Java的:  `量'

有差异,......