Created cross table query

Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
2017-07-01 10:32:25 +02:00
parent e5681a3db6
commit 6df559a9d5

View File

@ -118,7 +118,6 @@ public class ORM {
"VALUES (?, ?, ?, ?, ?)";
try {
PreparedStatement pstmt = _connection.prepareStatement(insertSQL);
for (Article article : articles) {
pstmt.setInt(1, article.get_articleID());
pstmt.setString(2, article.get_name());
@ -192,4 +191,37 @@ public class ORM {
e.printStackTrace();
}
}
// --- analysis part starts here
public List<Integer> getSalesCrossTable(int year) {
String querySQL = "SELECT COUNT(s.ID) AS sales, a.NAME AS article, sh.CITY AS city, d.QUARTER AS quarter " +
"FROM VSISP12.SALES AS s, " +
"VSISP12.DATETABLE AS d, " +
"VSISP12.SHOP AS sh, " +
"VSISP12.ARTICLE AS a " +
"WHERE s.DATEID = d.ID " +
"AND s.STOREID = sh.ID " +
"AND s.ARTICLEID = a.ID " +
"AND d.YEAR = " + year + " " +
"GROUP BY GROUPING SETS ( (), (sh.CITY), (a.NAME), (sh.CITY, a.NAME), " +
"(d.QUARTER, sh.CITY), (sh.CITY, a.NAME, d.QUARTER) )";
List<Integer> sales = new ArrayList<>();
try {
PreparedStatement pstmt = _connection.prepareStatement(querySQL);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
// TODO finish method
int salesnr = rs.getInt("sales");
String article = rs.getString("article");
String city = rs.getString("city");
int quarter = rs.getInt("quarter");
}
} catch (SQLException e) {
e.printStackTrace();
}
return sales;
}
}