错误代码:1054。未知栏' next_price'在'字段列表'

时间:2017-09-14 14:57:48

标签: mysql

尝试对此进行一些故障排除,但认为对于经验丰富的人来说可能很容易......但它会不断出现错误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

1 个答案:

答案 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