每当我运行此查询时,我总是得到相同的错误。 我尝试使用简单的查询来测试查询中是否有错误。 我还注意到,当我在查询中使用视图时发生了错误。
创建或替换视图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);
然后这是我使用的查询(非常简单),但我总是得到同样的错误。
选择a.dealer_name,a.dealer_code 来自v_vss_car_wash a
现在,这是错误消息
引起:org.eclipse.birt.data.engine.odaconsumer.OdaDataException:无法获取结果集元数据。 org.eclipse.birt.report.data.oda.jdbc.JDBCException: SQL语句不返回ResultSet对象。 SQL错误#1:'crmsdbdev.d.dealer_name'不在GROUP BY 中 ; com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:'crmsdbdev.d.dealer_name'不在GROUP BY中
答案 0 :(得分:0)
只需将相应的列添加到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);