尝试对此进行一些故障排除,但认为对于经验丰富的人来说可能很容易......但它会不断出现错误1054.目标是将两者相加并提供一个数字。
select sum(next_price)
from
(
select sum(sub.next_price)
from sub
left join account on account.acctid = sub.acctid
where sub.date_created >= curdate()
and sub.date_created < curdate()+1
and account.type <> 'internal'
UNION ALL
select sum(sub.next_price)*-1
from sub
left join account on account.acctid = sub.acctid
where sub.date_closed >= curdate()
and sub.date_closed < curdate()+1
and account.type <> 'internal'
) as Temp
group by next_price
答案 0 :(得分:1)
临时表next_price
中没有名称为Temp
的列,这就是您收到该消息的原因。
sum(sub.next_price)
不会为您创建名称为next_price
的列。
尝试此查询:
select sum(t.price) as next_price
from
(
select sum(sub.next_price) as price
from sub
left join account on account.acctid = sub.acctid
where sub.date_created >= curdate()
and sub.date_created < curdate()+1
and account.type <> 'internal'
UNION ALL
select sum(sub.next_price)*-1 as price
from sub
left join account on account.acctid = sub.acctid
where sub.date_closed >= curdate()
and sub.date_closed < curdate()+1
and account.type <> 'internal'
) as Temp as t
group by t.next_price