我试图在该主题中进行查询:JFreeChart using numeric query ORACLE
生成条形图,但我总是收到错误: java.sql.SQLException:JDBCCategoryDataset.executeQuery():从数据库返回的列不足。
我的代码如下:
SELECT CASE WHEN TIME>23.73 AND TIME<=24.0 THEN '23.73<TIME<=24.10'
WHEN TIME>24.10 AND TIME<=25.68 THEN '24.10<TIME<=25.68'
WHEN TIME>25.68 AND TIME<=27.36 THEN '25.68<TIME<=27.36'
ELSE '27.36<TIME'
END || ' with value '|| COUNT(*) v FROM SWIMMER
GROUP BY CASE
WHEN TIME>23.73 AND TIME<=24.10 THEN '23.73<TIME<=24.10'
WHEN TIME>24.10 AND TIME<=25.68 THEN '24.10<TIME<=25.68'
WHEN TIME>25.68 AND TIME<=27.36 THEN '25.68<TIME<=27.36'
ELSE '27.36<TIME' END
我做错了什么?
答案 0 :(得分:1)
上面引用的SQL会导致错误(使用SQL Fiddle来检查代码),因为两个case语句不匹配JFreeChart只是用错误消息重新抛出错误。
如果您的SQL是正确的,JFreeChart告诉您在结果集中需要额外的列,因为您将case语句与查询的总数连接起来,如果它有效,则只返回一列。
尝试使用此SQL:
SELECT time_range || ' with value ' || total as category, total
FROM (SELECT time_range, COUNT(*) AS total
FROM (SELECT CASE
WHEN TIME > 23.73
AND TIME <= 24.0 THEN
'23.73<TIME<=24.10'
WHEN TIME > 24.10
AND TIME <= 25.68 THEN
'24.10<TIME<=25.68'
WHEN TIME > 25.68
AND TIME <= 27.36 THEN
'25.68<TIME<=27.36'
ELSE
'27.36<TIME'
END AS time_range
FROM swimmer)
GROUP BY time_range)