嘿伙計們我有這個查詢
SELECT SUM(body), SUM(mice), SUM(sety) FROM
(
SELECT sum(body1) as body, sum(mice1) as mice, sum(sety1) as sety from utkani where hrac1 in(select hrac1 from skupina where id=66)
UNION ALL
SELECT sum(body2) as body, sum(mice2) as mice, sum(sety2) as sety from utkani where hrac2 in(select hrac1 from skupina where id=66)
)
我收到錯誤:
#1248 - Every derived table must have its own alias
你能幫我解決這個問題嗎?
uj5u.com熱心網友回復:
一個 deivd 表是你在第一個FROM子句之后的內容
因為它是一個 tbale,它必須是一個像 utkani 這樣的名字,但正如你所看到的,一個 t1 就足夠了
SELECT SUM(body), SUM(mice), SUM(sety) FROM
(
SELECT sum(body1) as body, sum(mice1) as mice, sum(sety1) as sety from utkani where hrac1 in(select hrac1 from skupina where id=66)
UNION ALL
SELECT sum(body2) as body, sum(mice2) as mice, sum(sety2) as sety from utkani where hrac2 in(select hrac1 from skupina where id=66)
) t1
uj5u.com熱心網友回復:
我認為您錯過了向正在查詢的虛擬表添加別名
SELECT SUM(body), SUM(mice), SUM(sety) FROM
(
SELECT sum(body1) as body, sum(mice1) as mice, sum(sety1) as sety from utkani where hrac1 in(select hrac1 from skupina where id=66)
UNION ALL
SELECT sum(body2) as body, sum(mice2) as mice, sum(sety2) as sety from utkani where hrac2 in(select hrac1 from skupina where id=66)
) as temp
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/328749.html
標籤:mysql
