2017-09-14 8 views
0

これはちょっとトラブルシューティングを試みましたが、経験豊富な人にとっては簡単かもしれないと思っていましたが、それでもエラー1054が発生します。単一の数字を入力してください。エラーコード:1054. 'フィールドリスト'の 'next_price'列が不明確

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

は、このクエリを試してみてください? –

+0

@KobyDouek nop、それはTempという一時的なテーブルなので、おそらく 'Temp.next_price'ですが、subはありません。 – teeyo

+1

あなたは組合の次の価格を別名にしませんでした。 'select sum(sub.next_price)'は 'select sum(sub.next_price)next_price'である必要があります。さらに、なぜnext_priceを集計してグループ分けしていますか? – xQbert

答えて

1

名前next_priceとは、カラムを使用すると、そのメッセージを取得している理由です、一時テーブルTempではありません。

sum(sub.next_price)名前がnext_priceの列は作成されません。それは `sub.next_price`ことshould't、あなたの最初の行で

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 
+0

私はその2番目の「tとして」とグループを落としました、そして、今働くようです!ありがとう – skyrunner

+0

@skyrunnerはい、一時テーブルのエイリアスを削除することができます。これはオプションです。読みやすくなります:)解決策として問題を解決した場合は、喜んで助けてください;)良い一日を – teeyo

関連する問題