[英]Can´t figure out the problem with MYSQL query
嘿伙计们我有这个查询
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
你能帮我解决这个问题吗?
一个 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
我认为您错过了向正在查询的虚拟表添加别名
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.