我試圖顯示從我的查詢中有3個表中的一個列中的列,但我似乎無法弄清楚如何讓它正常工作。無論我嘗試什麼,它似乎都不起作用。這似乎很容易,但也許我錯過了一些非常簡單的事情。以下是我有:如何在SQL查詢中顯示多個表中的列?
SELECT hpg.id_number,
hpg.id_description,
COUNT (hdd.number_of_games) games,
SUM (NVL (price, 0)) total,
SUM (number_of_food) food
--I tried adding column here, but nothing seemed to work
FROM (SELECT number_of_games, price, prints
FROM (hopeful_dog_hops)
WHERE status = 'Done') hdd,
(SELECT SUM (number_of_food) number_of_food, number_of_games
FROM hot_digity_dog
GROUP BY number_of_games) hdd1,
(SELECT id_description, sort_types, id_number
FROM (hot_pick_games)
WHERE disabled = 'TRUE' AND viewable_type = 'OK') hpg
WHERE hdd.prints(+) = hpg.id_number
AND hdd.number_of_games = hdd1.number_of_games
GROUP BY hpg.id_description, hpg.id_number, sort_types
ORDER BY sort_types
這個巨大的查詢顯示這些列:
ID_NUMBER ID_DESCRIPTION GAMES TOTAL FOOD
我需要增加一個列:從hot_digity_dog表
TEST
。
不要太擔心所有事情的名稱,但我只需要弄清楚我到底能夠在查詢中顯示另一列。我試着將TEST添加到第一個SELECT語句中,但它給了我一個錯誤:「TEST:無效標識符」。
我知道查詢的工作原理(沒有添加TEST部分,所以它不能成爲查詢中的錯誤)。它必須是新增加的部分。
任何幫助將不勝感激。提前致謝。
這裏是新列的查詢:
SELECT hpg.id_number,
hpg.id_description,
COUNT (hdd.number_of_games) games,
SUM (NVL (price, 0)) total,
SUM (number_of_food) food,
hdd.TEST
FROM (SELECT number_of_games, price, prints
FROM (hopeful_dog_hops)
WHERE status = 'Done') hdd,
(SELECT SUM (number_of_food) number_of_food, number_of_games
FROM hot_digity_dog
GROUP BY number_of_games) hdd1,
(SELECT id_description, sort_types, id_number
FROM (hot_pick_games)
WHERE disabled = 'TRUE' AND viewable_type = 'OK') hpg
WHERE hdd.prints(+) = hpg.id_number
AND hdd.number_of_games = hdd1.number_of_games
GROUP BY hpg.id_description, hpg.id_number, sort_types
ORDER BY sort_types
這裏是列標題應該是什麼樣子:
ID_NUMBER ID_DESCRIPTION GAMES TOTAL FOOD TEST
請出示您添加其他列的查詢。 –
嘗試添加適當的數據樣本和預期結果 – scaisEdge
您從不選擇hdd查詢中的TEST列。在那裏選擇它,以及'number_of_games,price,prints',我懷疑它會起作用。 – Zorkolot