Questions tagged [column-alias]

155 questions
104
votes
6 answers

Using an Alias column in the where clause in Postgresql

I have a query like this: SELECT jobs.*, ( CASE WHEN lead_informations.state IS NOT NULL THEN lead_informations.state ELSE 'NEW' END ) AS lead_state FROM jobs LEFT JOIN lead_informations…
troelskn
  • 115,121
  • 27
  • 131
  • 155
93
votes
5 answers

PostgreSQL: using a calculated column in the same query

I am having trouble using a calculated column in postgres. A similar code which works in SQL is given below, is it possible to recreate this in PostgreSQL? select cost_1, quantity_1, cost_2, quantity_2, (cost_1 * quantity_1) as total_1, …
user1146150
  • 931
  • 1
  • 6
  • 3
26
votes
3 answers

SQL not recognizing column alias in where clause

SQL is having an issue with the WHERE clause of this script: SELECT ITEM_ID, ITEM_PRICE, DISCOUNT_AMOUNT, QUANTITY, (ITEM_PRICE*QUANTITY) AS price_total, (DISCOUNT_AMOUNT*QUANTITY) AS discount_total, …
Somus
  • 263
  • 1
  • 3
  • 4
22
votes
2 answers

Are there any restrictions on Postgres column alias names?

Are there any restrictions, in terms of length, ability to include non-ASCII characters, etc. on the name of a Postgres column alias? And have there been any changes to such restrictions from version 8.1 to the present?
DNS
  • 37,249
  • 18
  • 95
  • 132
21
votes
3 answers

PostgreSQL - Aliases column and HAVING

SELECT CASE WHEN SUM(X.Count)*3600 is null THEN '0' ELSE SUM(X.Count)*3600 END AS PJZ, X.Mass FROM X WHERE X.Mass > 2000 HAVING ((X.Mass / PJZ * 100) - 100) >= 10; Getting: ERROR: Column »pjz«…
6EQUJ5HD209458b
  • 271
  • 1
  • 3
  • 12
17
votes
8 answers

SQL: What does NULL as ColumnName imply

I understand that AS is used to create an alias. Therefore, it makes sense to have one long name aliased as a shorter one. However, I am seeing a SQL query NULL as ColumnName What does this imply? SELECT *, NULL as aColumn
Shamim Hafiz - MSFT
  • 21,454
  • 43
  • 116
  • 176
13
votes
4 answers

Why can't I use column aliases in the next SELECT expression?

Can I modify the next to use the column aliases avg_time and cnt in an expression ROUND(avg_time * cnt, 2)? SELECT COALESCE(ROUND(stddev_samp(time), 2), 0) as stddev_time, MAX(time) as max_time, ROUND(AVG(time), 2) as avg_time, …
sergzach
  • 6,578
  • 7
  • 46
  • 84
9
votes
2 answers

Rename nested struct columns in a Spark DataFrame

I am trying to change the names of a DataFrame columns in scala. I am easily able to change the column names for direct fields but I'm facing difficulty while converting array struct columns. Below is my DataFrame schema. |-- _VkjLmnVop: string…
Vijay
  • 924
  • 1
  • 12
  • 27
6
votes
2 answers

Using CASE on a Calculated Column in SQL Server 2012

I have a database called temp, with daily stock prices: Ticker Date price ABC 01/01/13 100.00 ABC 01/02/13 101.50 ABC 01/03/13 99.80 ABC 01/04/13 95.50 ABC 01/05/13 78.00 XYZ 01/01/13 11.50…
Coding_Newbie
  • 365
  • 1
  • 3
  • 11
6
votes
2 answers

PostgreSQL - ERROR: column does not exist SQL state: 42703

I am trying to do a cohort analysis and compare average number of rentals based on the renter's first rental year(= the year where a renter rented first time). Basically, I am asking the question: are we retaining renters whose first year renting…
DBE7
  • 766
  • 2
  • 9
  • 23
5
votes
2 answers

How can I factor out repeated expressions in an SQL Query? Column aliases don't seem to be the ticket

So, I've got a query that looks something like this: SELECT id, DATE_FORMAT(CONVERT_TZ(callTime,'+0:00','-7:00'),'%b %d %Y') as callDate, DATE_FORMAT(CONVERT_TZ(callTime,'+0:00','-7:00'),'%H:%i') as callTimeOfDay, …
Weston C
  • 3,642
  • 2
  • 25
  • 31
5
votes
1 answer

Laravel 4 Eloquent Column Alias

What i am trying to achieve is in my database i have a table named channel i am using laravel's eloquent class to access these the properties from the table The problem that i am facing is that the table name is column and the column name is…
Lpc_dark
  • 2,834
  • 7
  • 32
  • 49
4
votes
1 answer

How to produce query results with automatic table aliases in MySQL?

MySQL ver 10 (MariaDB). PHP 5.6.3 libmysql 5.1.73 It's been a while for me working with Oracle but I vaguely remember that Oracle did exactly what I'm expecting in this example. I could be mistaken or maybe MySQL just isn't doing the same thing...…
jacekn
  • 1,521
  • 5
  • 29
  • 50
4
votes
4 answers

Oracle rename columns from select automatically?

I have 2 tables with the following fields. Table1 AA BB CC DD Table2 AA CC EE Query Select t1.*, t2.* from table1 t1, join table2 t2 on table1.DD = table2.EE My data columns back with the following column names: AA, BB, CC, DD,…
bwawok
  • 14,898
  • 7
  • 32
  • 43
4
votes
4 answers

Column alias not recognized in WHERE-statement

I have a strange 'problem' with one of my created queries. Given the next query: SELECT ID, DistanceFromUtrecht, ( SELECT (MAX(DateUntil) - (ReleaseDays * 60 * 60 * 24)) FROM PricePeriod WHERE PricePeriod.FK_Accommodation =…
Ben Fransen
  • 10,884
  • 18
  • 76
  • 129
1
2 3
10 11