Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

FIX: SQL statement not sorting ability name alphabetically #57

Open
mithi opened this issue Oct 29, 2020 · 0 comments
Open

FIX: SQL statement not sorting ability name alphabetically #57

mithi opened this issue Oct 29, 2020 · 0 comments

Comments

@mithi
Copy link
Owner

mithi commented Oct 29, 2020

This SQL statement is suppose to sort by tower name then by ability name, but it is not sorting by ability name

SELECT
ability_table."towerName" AS "towerName",
ability_table."abilityName" AS "abilityName",
ability_table."abilityDescription",
ability_table."totalAbilityCost",
ability_table."towerId",
ability_table."abilityId",
ability_table.kingdom,
ability_table."towerType",
ability_table."numberOfLevels",
ability_table."levelCosts",
(m4."buildCost" + m3."buildCost" + m2."buildCost" + m1."buildCost" + "totalAbilityCost") AS "totalCostWithTowers"
FROM build_sequence as bs
INNER JOIN "Towers" AS t4 ON t4.id = bs."level4Id" INNER JOIN main_stats AS m4 ON t4.id = m4.id
INNER JOIN "Towers" AS t3 ON t3.id = bs."level3Id" INNER JOIN main_stats AS m3 ON t3.id = m3.id
INNER JOIN "Towers" AS t2 ON t2.id = bs."level2Id" INNER JOIN main_stats AS m2 ON t2.id = m2.id
INNER JOIN "Towers" AS t1 ON t1.id = bs."level1Id" INNER JOIN main_stats AS m1 ON t1.id = m1.id
INNER JOIN (
    SELECT
        "Towers".name AS "towerName",
        ability.name AS "abilityName",
        ability.description AS "abilityDescription",
        SUM(cost) AS "totalAbilityCost",
        "Towers".id AS "towerId",
         ability.id AS "abilityId",
        "Towers".kingdom AS kingdom,
        "Towers"."towerType" AS "towerType",
        COUNT(ability_level.level) AS "numberOfLevels",
        ARRAY_AGG (ability_level.cost) "levelCosts"
    FROM "Towers"
        INNER JOIN ability ON ability."towerId" = "Towers".id
        INNER JOIN ability_level ON ability.id = ability_level."abilityId"
    GROUP BY "Towers".name, ability.name, "Towers".id, ability.id
) AS ability_table ON t4.name = ability_table."towerName"
WHERE 
  (t4.kingdom = 'kingdom rush' OR t4.kingdom = 'kingdom rush: frontiers' OR t4.kingdom = 'kingdom rush: origins' OR t4.kingdom = 'kingdom rush: vengeance') AND
  (t4."towerType" = 'barracks' OR t4."towerType" = 'archer' OR t4."towerType" = 'artillery' OR t4."towerType" = 'mage') 
ORDER BY "towerName" ASC, "abilityName" ASC 
LIMIT 104 OFFSET 0

SAMPLE RESULT

{
  "data": {
    "abilities": [
      {
        "towerName": "500mm big bertha",
        "abilityName": "cluster launcher xtreme",
        "kingdom": "KR"
      },
      {
        "towerName": "500mm big bertha",
        "abilityName": "dragonbreath launcher",
        "kingdom": "KR"
      },
      {
        "towerName": "arcane archers",
        "abilityName": "Slumber Arrows",
        "kingdom": "KRO"
      },
      {
        "towerName": "arcane archers",
        "abilityName": "burts arrors",
        "kingdom": "KRO"
      },
      {
        "towerName": "arcane wizard",
        "abilityName": "death ray",
        "kingdom": "KR"
      },
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant