TSB
TSB

Reputation: 11

Alias in select yields

Running a simple query like the following yields "Error Code: 1054, Unknown column 'GDP_PPP' in 'field list'

SELECT
COUNTRY
, POPULATION
, GDP_PPP_MIL
, GDP_PPP_MIL * 1E6 AS GDP_PPP
, GDP_PPP / POPULATION
FROM COUNTRIES

I am using mysql v5.7.12 and MySQL Workbench 6.3 on OS X 10.11.4 (El Capitan). I just downloaded it a few days ago, then upgraded the OS to El Cap.

Upvotes: 1

Views: 18

Answers (2)

Andrews B Anthony
Andrews B Anthony

Reputation: 1381

The column you just naming(alias) would not reflect in the query

Some alternatives

1.to use the formula again

SELECT
COUNTRY
, POPULATION
, GDP_PPP_MIL
, GDP_PPP_MIL * 1E6 AS GDP_PPP
, GDP_PPP_MIL * 1E6/ POPULATION
FROM COUNTRIES

Upvotes: 1

Have you tried this ?

SELECT COUNTRY , POPULATION , GDP_PPP_MIL , GDP_PPP_MIL * 1E6 AS 'GDP_PPP' , GDP_PPP / POPULATION FROM COUNTRIES

Upvotes: 0

Related Questions