0

I was trying to make a query like in that topic: JFreeChart using numeric query ORACLE

to generate a barchart, but i am always receiving that error: java.sql.SQLException: JDBCCategoryDataset.executeQuery() : insufficient columns returned from the database.

My code is as follow:

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

What i am doing wrong?

4

1 回答 1

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)
于 2013-05-09T08:32:26.793 回答