Extended cross table query to allow different entries for location dimension

Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
Jim Martens 2017-07-05 13:34:32 +02:00
parent 8e4b359762
commit e601db107e
2 changed files with 15 additions and 9 deletions

View File

@ -13,16 +13,17 @@ public class MainAnalysis {
public static void main(String[] args) {
_orm = new ORM();
Map<String,Map<String, Map<String, Integer>>> sales = _orm.getSalesCrossTable(2017,
"PRODUCTFAMILY");
"PRODUCTFAMILY",
"NAME");
printTable(sales);
}
private static void printTable(Map<String, Map<String, Map<String, Integer>>> crossTable) {
List<String> articleNames = new ArrayList<>(crossTable.get("total").get("total").keySet());
Collections.sort(articleNames);
StringBuilder columnHeaderEdge = new StringBuilder("+-----------------+-----------------+");
StringBuilder columnHeader = new StringBuilder("| Location | Time |");
StringBuilder leftAlignFormat = new StringBuilder("| %-15s | %-15s |");
StringBuilder columnHeaderEdge = new StringBuilder("+------------------------+-----------------+");
StringBuilder columnHeader = new StringBuilder("| Location | Time |");
StringBuilder leftAlignFormat = new StringBuilder("| %-22s | %-15s |");
for (String article : articleNames) {
if (article.equals("total")) continue;

View File

@ -202,10 +202,14 @@ public class ORM {
* @param year the year to be queried
* @param productDimension the column of the productDimension to be used (name for article name, productgroup,
* productfamily, productcategory)
* @param locationDimension the column of the locationDimension to be used (name for shop name, city, region, country)
* @return the cross table
*/
public Map<String,Map<String, Map<String, Integer>>> getSalesCrossTable(int year, String productDimension) {
String querySQL = "SELECT SUM(s.SOLDUNITS) AS sales, a." + productDimension + " AS article, sh.CITY AS city, " +
public Map<String,Map<String, Map<String, Integer>>> getSalesCrossTable(int year,
String productDimension,
String locationDimension) {
String querySQL = "SELECT SUM(s.SOLDUNITS) AS sales, a." + productDimension + " AS article, sh." +
locationDimension + " AS city, " +
"d.QUARTER AS quarter " +
"FROM VSISP12.SALES AS s, " +
"VSISP12.DATETABLE AS d, " +
@ -215,9 +219,10 @@ public class ORM {
"AND s.STOREID = sh.ID " +
"AND s.ARTICLEID = a.ID " +
"AND d.YEAR = " + year + " " +
"GROUP BY GROUPING SETS ( (), (sh.CITY), (a." + productDimension + "), " +
"(sh.CITY, a." + productDimension + "), " +
"(d.QUARTER, sh.CITY), (sh.CITY, a." + productDimension + ", d.QUARTER) )";
"GROUP BY GROUPING SETS ( (), (sh." + locationDimension + "), (a." + productDimension + "), " +
"(sh." + locationDimension + ", a." + productDimension + "), " +
"(d.QUARTER, sh." + locationDimension + "), " +
"(sh." + locationDimension + ", a." + productDimension + ", d.QUARTER) )";
Map<String,Map<String, Map<String, Integer>>> sales = new HashMap<>();
try {