Questions tagged [column-alias]
155 questions
3
votes
3 answers
PostgreSQL - why can't I ORDER BY a function of a column?
I'm trying to get something I thought should be relatively simple (it works in Oracle and MySQL). The PostgreSQL fiddle for the code below is available here - just change the server to check out the others.
Very simple test case:
CREATE TABLE x
(
…

Vérace
- 854
- 10
- 41
3
votes
2 answers
Divide by 'Over' clause in MSSQL works but divide by 'Alias' does not
In MS SQL Server, I spent too much time trying to resolve this. I finally figured it out, except I don't know the reason. How come, dividing by the cast statement in line 4 works below
SELECT
cast(dbo.FACTINVOICEHEADER.TOTAL_NET_AMOUNT_AMOUNT…

BrianBeing
- 431
- 2
- 4
- 12
3
votes
2 answers
Column does not exist in psql
I am trying to filter out days with more than 1% error rates for a website. I already have a table that shows the individual days with their respective error rates, but when I try to include a "where" or "having" clause to filter out the days with a…

Diego Villafuerte
- 69
- 3
3
votes
0 answers
Full alias for table columns in ActiveRecord
I want something like alias_attribute for make a full alias for column from DB. For example I have a table with many columns named like UGLYCOLUMN.
Using it in a query is very uncomfortable:
MyModel.where('UglyColumn'.upcase => 'value')
I want…

user3240646
- 123
- 9
2
votes
2 answers
sql left join for two tables using a CONCAT string as the argument
I need to get a title from table 2, table 2 has title and id column.
Table 1 has some data and three of these columns concatenated together makeup the id that can be found in table 1.
I used CONCAT_WS() function and gave this column an alias name…

Beyerz
- 787
- 2
- 9
- 20
2
votes
1 answer
Can i use 'alias' AS in CASE Statement PostgreSQL
SELECT
id
, quantity
, unit_price
, (antity * unit_price) as price
CASE
WHEN quantity * unit_price > 5000 THEN (quantity * unit_price) * 0.2
WHEN quantity * unit_price > 3000 THEN (quantity * unit_price) * 0.15
…

Uncle_Moris
- 83
- 4
2
votes
2 answers
Can't filter by alias
created_at - type timestamp with timzone
Query:
select id,
created_at,
extract(epoch from CURRENT_TIMESTAMP - created_at) as delta_sec
from shop_order
Success work. Nice.
Now I want to show only records where delta_sec >…

Alexei
- 14,350
- 37
- 121
- 240
2
votes
1 answer
Using equals in a select clause to set column aliases
Today I saw someone using this syntax (A) to set column aliases in a sql select.
A
Select [ColumnAlias] = Column1 FROM Table
B
Normally I use
Select Column1 AS [ColumnAlias] FROM Table
I've used = to set local variables, but never as aliases.…

w00ngy
- 1,646
- 21
- 25
2
votes
1 answer
Query to insert row number to paginate results
I try to execute a query which takes all data from a table. I would like to use pagination as their is a constration in the results. So I try to insert pagination in the query like this
What I tried is this
Select ROW_NUMBER() OVER (ORDER BY…

Nathalie
- 1,228
- 7
- 20
2
votes
3 answers
Why is SQL Server not catching this? Typo in subquery causes accidental delete
I have a query with a subselect where I mistyped a column (id1 in the subselect). If the query is executed separatly SQL Server throws an error, which is correct and expected. However if executed as a subquery in the below context the typo is not…

Peter Sawatzki
- 173
- 7
2
votes
3 answers
column does not exist error even when using the 'as' keyword
I get this error:
ERROR: column "errors" does not exist
LINE 11: where errors >= 1
even that i checked the result with select.
I'm using postgresql server, i have a table named log like the following:
Column | Type | …

OSEMA TOUATI
- 327
- 2
- 13
2
votes
4 answers
Oracle merging column is giving error
I have 2 columns in oracle, that I am merging like below
select SURVEY_AREA_7_12 || ' ' || HISSA_NO_7_12
from XXCUS.XXACL_PN_FARMING_MST
which is working fine. But when I add my own name to the columns like below
select SURVEY_AREA_7_12 || ' ' ||…

Nad
- 4,605
- 11
- 71
- 160
1
vote
0 answers
How to insert data into table with case expression?
How do I insert data into a table that I created using a case expression?
Tutorial i am reading
Im trying to populate the table only with the high popularity movie categories.
INSERT INTO category_summary (most_popular)
SELECT category_name,…

Stack Ty
- 51
- 7
1
vote
1 answer
How to change default column name for Conditional Expressions
I am referring to this document -> https://www.postgresql.org/docs/current/functions-conditional.html
SELECT a,
CASE WHEN a=1 THEN 'one'
WHEN a=2 THEN 'two'
ELSE 'other'
END
FROM test;
a |…

Rey4eel
- 27
- 7
1
vote
1 answer
Language dependent column headers
I am working on an PostgreSQL based application and am very curious if there might be a clever solution to have language dependent column headers.
I sure know, that I can set an alias for a header with the "as" keyword, but that obviously has to be…

Marc Rohrer
- 41
- 1