Questions tagged [column-alias]
155 questions
1
vote
1 answer
PostgreSQL - Escape single quote in an column alias
How to escape single quote in an column alias in PostgreSQL?
I tried several syntaxes without success:
SELECT 'Test 1' AS 'O''Connell';
SELECT 'Test 2' AS 'O\'Connell';
SELECT 'Test 3' AS "O''Connell";
PgAdmin screenshot

GeoGyro
- 487
- 12
- 32
1
vote
3 answers
invalid identifier : sum of multiple column in sql
I'm trying to calculate multible columns in this query
SELECT
SUM (CASE WHEN B.ID = 1 THEN 1 END) AS OPD,
SUM (CASE WHEN B.ID = 2 THEN 1 END) AS IPD,
SUM (CASE WHEN B.ID = 3 THEN 1 END) AS DC,
SUM…

Hamda
- 63
- 9
1
vote
2 answers
How to give alias for columns with same name after joining two tables in Postgres
Hi Guys I'm doing inner join for two tables and selecting all the columns from both tables. But I'm getting three cols with same name like id, created_at and updated_at.
Query:
SELECT addresses.* , facilities.* FROM facilities
INNER JOIN…

Nikhil Attar
- 105
- 11
1
vote
1 answer
how to give an aliasname to like operator in mysql
I want to select the name like 'Bo%' or name like 'Ni%' from a table and I want to give a specific name to all that name like Bo and a specific name to all that name like Ni.
But if I give an alias name as this it not works.
name like 'Bo%' as Male…

kanchana
- 11
- 1
- 3
1
vote
1 answer
PostgreSQL: ERROR: column "bb" does not exist
I am not good at SQL, I wanted to take MAX using partition by in the following query, but when I use the same query without where clause of that max drive column it says that column does not exist but if I remove the column from where I can see in…

Indrajeet Gour
- 4,020
- 5
- 43
- 70
1
vote
3 answers
Using LENGTH(computed column) in ORDER BY in Postgres sql
SELECT concat(first_name,last_name) AS full_name from customer
ORDER BY length(full_name);
I tried to run this in postgre sql database.
I give me this erro
[42703] ERROR: column "full_name" does not exist
How would I resolve this? Order rows…

Shawn99
- 15
- 4
1
vote
2 answers
Can't use column alias in GROUP BY
I can run this in mysql with no problem
SELECT
DATE_FORMAT(trans_date, '%Y-%m') month,
COUNTRY, COALESCE(COUNT(*), 0) trans_count,
COALESCE(SUM(CASE WHEN state ='approved' THEN 1 END), 0) approved_count,
COALESCE(SUM(amount), 0)…

victorlifan
- 27
- 1
- 6
1
vote
2 answers
How to use new created column in where column in sql?
Hi I have a query which looks like the following :
SELECT device_id, tag_id, at, _deleted, data,
row_number() OVER (PARTITION BY device_id ORDER BY at DESC) AS row_num
FROM…

Mustufain
- 198
- 12
1
vote
1 answer
SQL Filter not working with alias in statement
I keep getting errors when trying to execute my statement, saying the following:
ERROR [42703] [IBM][DB2/LINUXX8664] SQL0206N "HAO" is not valid in the context where it is used.
Error is referring to my filters as it works fine when commented…
user10641490
1
vote
2 answers
Conditional Query Using "AS" field
SELECT "public"."mv_tags_per_org"."count" AS "count", "public"."mv_tags_per_org"."tag_name" AS "Tag Name",
CASE
WHEN "public"."mv_tags_per_org"."ngo_id" = 30 then 'SSS'
WHEN "public"."mv_tags_per_org"."ngo_id" = 33 then 'PF'
WHEN…
user12075259
1
vote
2 answers
Deriving new column using new column
Normally we can build new columns in Select statements. Is it possible to derive new columns out of new columns in Select statements?
For example,
Select 1+2 A
This gives us a table with column A and the value 3 in 1 row.
Can I build a new column B…

Victor Ng
- 71
- 3
1
vote
2 answers
Use Expression Result (e.g. Month) as Column Name in SQL Express
I'm writing an SQL expression and I'd like to use the current month as the column name/header.
Code:
Select MONTH(GETDATE()) AS MONTH(GETDATE())
FROM SomeTable;
Error:
Error 102: Incorrect syntax near 'GETDATE'.
This is for a school project and…

Lifes
- 1,226
- 2
- 25
- 45
1
vote
0 answers
Conditional expression, postgresql, get the result from the case
Looking at conditional expressions in Postgresql. To be more precise, this example.
SELECT * FROM test;
a
---
1
2
3
SELECT a,
CASE WHEN a=1 THEN 'one'
WHEN a=2 THEN 'two'
ELSE 'other'
END AS amod
FROM…

Orjanp
- 10,641
- 12
- 36
- 39
1
vote
2 answers
mysql use column aliases read from database
I want to display names for columns in another table like so :
select data.data1 as head.colHeader1, data.data2 as head.colHeader2 from DATA_TABLE data, HEADER_TABLE head where data.Key = header.Key and header.key = 'someUniqueKey'
the above query…

neggenbe
- 1,697
- 2
- 24
- 62
1
vote
2 answers
use column alias which have over(partition) in where clause
Hi can anyone help me in this query, how to add total_pallet_id >= 80 in where statements.
Thanks for your kind help, much appreciate.
user7170424