Questions tagged [column-alias]
155 questions
0
votes
3 answers
PostgreSQL Syntax Error near JOIN, or anyother
I have this Olympics Dataset which i imported on PostgreSQL database. I want to Create table using select statement and somemore is there. But I'm getting this error:
ERROR: column foo.age does not exist
LINE 17: (case when foo.Age=NULL then…

swapnil
- 21
- 5
0
votes
1 answer
Postgres INNER JOIN ERROR: schema "bar" does not exist
I am trying to do an inner join between two tables, foo and bar. the relation is one-to-many. a bar needs a foo, and a foo can have any number of bars. Confusingly, both tables have columns named "name" and "id". When I run my query, I'd like to…

A. Davidson
- 397
- 1
- 4
- 14
0
votes
2 answers
How to use the alias of my calculated parameter (in SELECT clause) in WHERE clause with PostgreSQL to prevent repetition?
In the query below, the parameter date_part('year', CURRENT_DATE) - f.birth_year is repeated three times. How can I replace it by its alias age ?
SELECT
date_part('year', CURRENT_DATE) - f.birth_year AS age
FROM
public.foo f
WHERE
…

DevonDahon
- 7,460
- 6
- 69
- 114
0
votes
5 answers
How to get a Full name as an Alias and use it in a Like statement
Hi everyone this is my first time in a Forum like this. I'm from Germany so English is not my native language so don't be too harsh with me please :).
Select top(1) firstname+' '+lastname AS APName
From ansprech
Where customernr = 10205 and APName…

Pierre1994
- 11
- 1
0
votes
1 answer
How to use row_number in a where clause
I'm trying to use window functions to get the most recent n records, following from here:
I have:
select
id,
blah,
row_number () over (
partition by blah, my_id
order by datetime) rn,
theme
from documents
where theme =…

Mittenchops
- 18,633
- 33
- 128
- 246
0
votes
1 answer
Type cast a field created on-the-fly using AS "new_field" in a SELECT subquery
Context
I have a really tiny issue while creating a PostgreSQL table using a SELECT sub-query where I'd like to initialize a field with NULL values of type INTEGER (they default to TEXT if I do not specify the type).
Enough talking, here is the…

swiss_knight
- 5,787
- 8
- 50
- 92
0
votes
2 answers
Column not recognized in select statement
Im getting an error in the Select statement of this code.
SELECT Track.Name, Track.UnitPrice,
Count(*) AS Purchase_count,
Purchase_count * Track.UnitPrice AS Total_per_track
FROM Track
JOIN InvoiceLine ON Track.TrackId =…

ThatDickmanGuy
- 3
- 1
0
votes
2 answers
Use column named using 'AS' clause in next column definition
How would I use the column I defined as 'total_affected' in place of the long function?.. I feel like there is a better way to do this rather than to repeat the same thing from the previous line. I am not sure how to define it so I can use it right…

Jack Avante
- 1,405
- 1
- 15
- 32
0
votes
0 answers
How to filter on an alias column in postgres?
I am new to Postgres & I am facing difficulty in this query:
I have this query:
SELECT "employees_employee"."primary_title",
"employees_employee"."primary_role_id",
"employees_organization"."benchmark_organization_id" AS…

Mohan
- 4,677
- 7
- 42
- 65
0
votes
2 answers
Use column alias in WHERE clause
I have a function in my query that uses a column in my table and results in a unique number for that input.
SELECT FunctionResultsinUniqueNumber(t.[table1Column]) AS Col1
FROM Table1 t
I would also like to join another table which already has…

pty
- 121
- 7
0
votes
0 answers
How to get median for time interval in Postgres?
Consider this:
SELECT
review.clicker_id,
sum(review.done - review.due) as timespent,
PERCENTILE_DISC(0.5) WITHIN GROUP(ORDER BY timespent ASC) as median
FROM review WHERE monologue_id=7142 GROUP BY clicker_id ORDER BY timespent ASC;
I'm…

Fabien Snauwaert
- 4,995
- 5
- 52
- 70
0
votes
1 answer
What does SUMMARY DESCRIPTION command perform in Oracle SLECT query
I have a SELECT query that fetches some data from table but there is one line I can't understand at all . Can anyone tell me what does SUMMARY DESCRIPTION doing in my query cause I have no idea . Please Help .
SELECT alarms.ALARMID,
…

Maximious
- 155
- 2
- 12
0
votes
2 answers
How to escape square brackets in column alias?
The following yields error:
SELECT 1 AS [dada[daa]]
Msg 105, Level 15, State 1, Line 190 Unclosed quotation mark after the
character string 'dada[daa] '.
Msg 102, Level 15, State 1, Line 190
Incorrect syntax near 'dada[daa] '.
and if I have…

gotqn
- 42,737
- 46
- 157
- 243
0
votes
1 answer
Does Redshift support User-Defined Variables in SELECT?
I'm reviewing some of our Redshift queries and found cases with multiple levels of nested select like the one below:
LEFT JOIN
(
SELECT *
FROM (
SELECT
id,
created_at,
…

user1525248
- 183
- 1
- 1
- 8
0
votes
1 answer
Column aliasing while copying a table in oracle
Hi I was copying a employees table in HR schema with query:
Create table copy_employees as ( select last_name,salary*12 from employees);
But the error shows that salary needs to be aliased.
After I did salary*12 as sal it worked.
My question is…

Atul Singh
- 9
- 2