【发布时间】:2015-04-25 05:49:36
【问题描述】:
我正在使用 JDBC 和 PostgreSQL,我必须执行以下操作:
/*
* Return list of film titles whose length is equal to or greater
* than the minimum length, and less than or equal to the maximum
* length.
*/
public List<String> getFilmTitlesBasedOnLengthRange(Connection connection,
int minLength, int maxLength) {
List<String> result = new LinkedList<String>();
return result;
}
我尝试通过在 PostgreSQL 中编写查询来解决这个问题(甚至不确定它是否正确):
SELECT title
FROM dv_film A, dv_film B
WHERE (A.length >= (COUNT(length) ASC LIMIT 1)) AND (B.length >= (COUNT(length) DESC LIMIT 1));
dv_film 关系为:
CREATE TABLE dv_film (
film_id integer,
title varchar(50),
description text,
length smallint,
rating mpaa_rating
);
我试图解决这个问题的尝试是:
public List<String> getFilmTitlesBasedOnLengthRange(Connection connection,
int minLength, int maxLength) {
List<String> result = new LinkedList<String>();
PreparedStatement st = conn.prepareStatement("SELECT title FROM dv_film A, dv_film B WHERE (? >= (COUNT(length) ASC LIMIT 1)) AND (? >= (COUNT(length) DESC LIMIT 1));");
return result;
}
【问题讨论】:
标签: postgresql jdbc