Questions tagged [column-alias]
155 questions
0
votes
3 answers
Referencing a calculated field in SQL statement
I have the following schema
CREATE TABLE QUOTE (id int, amount int);
CREATE TABLE QUOTE_LINE (id int, quote_id int, line_amount int);
INSERT INTO QUOTE VALUES(1, 100);
INSERT INTO QUOTE VALUES(2, 200);
INSERT INTO QUOTE VALUES(3, 100);
INSERT…

Saqib Ali
- 3,953
- 10
- 55
- 100
0
votes
2 answers
Why a postgresql case statement's result does not work inside where clause
I am solving a PostgreSQL problems in this site.
My answer is:
select concat(mem.firstname, ' ', mem.surname), fac.name as facility,
case when mem.memid=0 then bks.slots*fac.guestcost
else bks.slots*membercost
end as cost
from cd.members…

cinmoy
- 31
- 2
0
votes
4 answers
Why can't I use my column alias in WHERE clause?
I want to compare a value of my current row with the value of the row before. I came up with this, but it won't work. It can't find PREV_NUMBER_OF_PEOPLE so my WHERE clause is invalid. I'm not allowed to use WITH. Does anyone have an idea?
SELECT
…
0
votes
2 answers
Using the alias from the select in the WHERE clause leads to error : "Missing FROM-clause entry for a table"
I'm a newbie at SQL and I can't manage to make the following sql query to work ! There seem to be an issue with the alias and the where clause but I don't find any workaround...
Could someone enlighten me ?
Table t_adresse (SCHEMA ab)
-------
…

wanderzen
- 119
- 2
- 12
0
votes
0 answers
Does timestamp.column.name support alias in PostgreSQL Source Connector?
I am joining two tables and fetching data in Kafka. If I use mode as a bulk then it works fine but if I use mode as timestamp and give timestamp.column.name accordingly then it shows
My configuration goes like this:
"name": "join-test-31",
…

Sajita
- 41
- 5
0
votes
2 answers
PostgreSQL - column does not existERROR: column "ins_file_url" does not exist
I have this query in PostgreSQL:
SELECT cars.*,
manufacturers.company_name AS manufacturer_company_name,
companies.mailing_name AS company_mailing_name,
(SELECT car_documents.file_url FROM car_documents
WHERE…

user984621
- 46,344
- 73
- 224
- 412
0
votes
1 answer
Column alias is not recognized
This minimal example is supposed to extract year from time stamps, then count something in a given year.
SELECT EXTRACT(YEAR FROM rental_ts) as year,
COUNT(DISTINCT rental_id)
FROM rental
GROUP BY year
HAVING year=2020
Running it, I get an…

icemtel
- 412
- 5
- 12
0
votes
1 answer
Works in MySQL but fails in Postgresql - having statement
I have the query below which works in MySQL but fails in Postgresql with the following error:
ERROR: column "status" does not exist
How do we implement this in Postgresql?
select
devices.*,
CASE
WHEN devices.retired = false
…

TheRealPapa
- 4,393
- 8
- 71
- 155
0
votes
2 answers
Referencing a column alias in the WHERE clause
Is there any way to return an "AS" result using WHERE or otherwise?
I'm doing a SUBSTRING on the FONE1 column and trying to return the DDD = 31 but I get the error,
Code: 1054. Unknown column 'DDD' in 'where clause' 0.000 sec
-->
SELECT …

Mr Poke
- 25
- 5
0
votes
1 answer
How to assign value to a variable in select query in postgresql
I am migrating from mssql to postgresql
I am trying to assign a value to a temporary variable in select query
Below is the query in mssql
select flag = 0
It gives 0 as output wit flag as column identifier in mssql
I tried the following in…

Rlaks
- 7
- 1
- 5
0
votes
0 answers
Alias not available with GROUP BY while ORDER BY is working fine
The main idea here is to extract json values from a column (genre tags from a Movie DB) and create a new table containing all the genres. This is done in serveral step, first I checked the max genre for a movie (here 7), then generate 7 tables to…

Tom97531
- 512
- 7
- 14
0
votes
0 answers
Can't filter by nodes in field with type jsonb
Table has two columns: id and data.
Column data has type jsonb
json :
"weight": {
"qty": 300,
"unit": {
"name": "gram",
"title": {
"en": "g"
}
}
I want to filter by json's nodes weight and qty.
Here…

Alexei
- 14,350
- 37
- 121
- 240
0
votes
1 answer
Will you help me find the I cannot seem to cast as integer?
All I am trying to do is pull the most recent 'Scan' (hence 'LastScan') from each 'location' and then find out if any of them are 2 hours or more 'old'(which would make them overdue).
Select cast(max(entered_date) as int) as 'LastScan',…

SkeerNC
- 1
- 1
0
votes
2 answers
How to match results of TRIM to column in table for a JOIN
See the original question and code further down. Here is the code that works:
SELECT v1.s_owner_guid,
n.node_name as s_owner_name
FROM vm_list v
CROSS JOIN LATERAL (
SELECT (VALUES (TRIM(split_part(v2.set_of_guids, ':', 3), '|')))
…

Jeffrey Johnson
- 13
- 3
0
votes
3 answers
Error in using Case Expression in select statement while we used join in statements
This code doesn't work and showing error "From keyword not found where expected"
select m.marks,
CASE
WHEN m.marks<65 then 'F'
WHEN m.marks>65 then 'P'
END m.grade
from student s INNER JOIN marks m ON s.id=m.id;
But this works
select marks,…

saikumar
- 21
- 2