在mysql中运行以下查询时,它的工作正常。
SELECT
a.feed_date, a.partner_name,
SUM(a.count) as InputCount,
SUM(CASE when (b.count is null) then 0 else b.count end) as OutputCount
FROM
(SELECT year,week,partner_name, feed_date, count
FROM op_dev.op_stats
WHERE partner_name IN ('xyz, INC.','abc')
AND mkt_elig_cd='Y'
AND rel_grp_type_no='00000'
AND feed_type='SellerChar') AS A
LEFT OUTER JOIN
(SELECT year,week,feed_date, partner_name, count
FROM opt_dev.op_stats
WHERE partner_name IN ('xyz, INC.','abc')
AND mkt_elig_cd='Y'
AND rel_grp_type_no='00000'
AND feed_type='MSF') AS B
ON A.partner_name = B.partner_name
AND A.year=B.year
AND A.week=B.week
GROUP BY A.week,A.year;
但是,当我使用相同的查询字符串并通过Java代码调用它时,它会给我以下错误:
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
有人可以帮我指出造成这个问题的原因。
答案 0 :(得分:1)
看起来你试图执行查询并指定参数(检查java和hibernate),但查询没有参数。
答案 1 :(得分:0)
GROUP BY子句必须包含选定的列。如果未选择任何列,则GROUP BY子句可以使用任何列。 你可以试试这个:
SELECT partner_name, feed_date,
SUM(CASE WHEN feed_type='SellerChar' THEN count ELSE 0 END) OVER(PARTITION BY year,week,feed_type) AS InputCount,
SUM(CASE WHEN feed_type='MSF' THEN count ELSE 0 END) OVER(PARTITION BY year,week,feed_type) AS OutputCount
FROM op_dev.op_stats
WHERE partner_name IN ('xyz, INC.','abc')
AND mkt_elig_cd='Y'
AND rel_grp_type_no='00000'
AND (feed_type='SellerChar' OR feed_type='MSF')