Squirrel和Jasper SQL结果不同

时间:2016-12-19 14:08:23

标签: mysql sql jasper-reports

我正在Jasper中进行查询,我需要从数据库中获取两个字段。查询是:

SELECT DISTINCT b.proto, SUM(type_count) AS count
FROM view_result a
JOIN (SELECT DISTINCT photo, count(*) AS type_count
FROM load_result
GROUP BY proto) b
ON a.proto = b.proto
WHERE id IN
(SELECT DISTINCT id
FROM survey
WHERE survey.file_name IN (list of file names)
GROUP BY proto

此查询在Squirrel中完美运行。但是,如果我应该采用相同的查询并在Jasper中使用它:

SELECT DISTINCT b.proto, SUM(type_count) AS count
FROM view_result a
JOIN (SELECT DISTINCT photo, count(*) AS type_count
FROM load_result
GROUP BY proto) b
ON a.proto = b.proto
WHERE id IN
(SELECT DISTINCT id
FROM survey
WHERE ${IN, a.file_name, file_names}
GROUP BY proto

(其中file_names是字符串列表,就像在Squirrel版本中一样), 我得到了一组完全不同的结果。这些查询不是真的相同吗?我正在使用完全相同的文件和所有内容,所以我看不出为什么这不应该起作用的原因。

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

第一个查询在IN子句中使用survey.file_name,第二个查询使用a.file_name