databasename.d.first_column_in_the_table' 不在 GROUP BY 中

databasename.d.first_column_in_the_table' isn't in GROUP BY

每当我 运行 这个查询时,我总是得到同样的错误。 我尝试使用简单的查询来测试查询中是否有问题。 我还注意到当我在查询中使用视图时发生了错误。

创建或替换视图 v_vss_car_wash AS

     SELECT
     max(r.id) AS id
    ,d.id AS dealer_id
    ,d.dealer_code
    ,d.dealer_name
    ,count(*) AS total_respondents
    ,sum(car_washed) AS car_washed                  -- Car Washed
    ,count(*) - sum(car_washed) AS car_unwashed     -- Car Unwashed
    ,sum(IF (car_washed AND car_satisfied, 1, 0)) AS car_satisfied
    ,sum(IF (car_washed AND NOT car_satisfied, 1, 0)) AS car_unsatisfied
    ,MONTH(r.create_date) AS create_month
    ,YEAR(r.create_date) AS create_year
FROM t_vss_survey_response r 
    LEFT JOIN t_vss_dealer d ON (r.dealer_id = d.id)
WHERE survey_code = "ASS"
GROUP BY dealer_code, YEAR(r.create_date), MONTH(r.create_date);

那么这是我正在使用的查询(非常简单),但我总是得到同样的错误。

select a.dealer_name, a.dealer_code 来自 v_vss_car_wash 一

现在,这是错误信息

原因:org.eclipse.birt.data.engine.odaconsumer.OdaDataException:无法获取结果集元数据。 org.eclipse.birt.report.data.oda.jdbc.JDBCException: SQL 语句没有 return 一个 ResultSet 对象。 SQL 错误 #1:'crmsdbdev.d.dealer_name' 不在 GROUP BY 中 ; com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 'crmsdbdev.d.dealer_name' 不在 GROUP BY

只需将适当的列添加到 group by:

CREATE OR REPLACE VIEW v_vss_car_wash AS
SELECT
     max(r.id) AS id
    ,d.id AS dealer_id
    ,d.dealer_code
    ,d.dealer_name
    ,count(*) AS total_respondents
    ,sum(car_washed) AS car_washed                  -- Car Washed
    ,count(*) - sum(car_washed) AS car_unwashed     -- Car Unwashed
    ,sum(IF (car_washed AND car_satisfied, 1, 0)) AS car_satisfied
    ,sum(IF (car_washed AND NOT car_satisfied, 1, 0)) AS car_unsatisfied
    ,MONTH(r.create_date) AS create_month
    ,YEAR(r.create_date) AS create_year
FROM t_vss_survey_response r 
    LEFT JOIN t_vss_dealer d ON (r.dealer_id = d.id)
WHERE survey_code = "ASS"
GROUP BY d.id, d.dealer_code, d.dealer_name,
         YEAR(r.create_date), MONTH(r.create_date);