Questions tagged [column-alias]

155 questions
0
votes
0 answers

Unable to access data in Postgres query where clause

I am dealing with the following JSON in a Postgres database column called steps in a table called tCampaign : [ { "name":"Step 1", "stepReference":"01e9f7c0-bc79-11eb-ab6f-2fa1cb676e38", "rewardConditions": [ …
richie
  • 21
  • 2
0
votes
2 answers

using column alias in where clause MySQL

I have two queries run on mysql. The first one returns an error while the seconds one returns an empty set and no error happens. SELECT CONCAT_WS(',' , firstName, lastName) `Full Name` FROM employees WHERE `Full Name` LIKE '%on'; ERROR 1054…
Farhad
  • 12,178
  • 5
  • 32
  • 60
0
votes
2 answers

Column announced with "as" does not exists SQL

I used column "as budget", however after that when trying to use it in when section in reports that "There is no column budget". Here is the code: select p.id, p.budget/365 as budget, SUM(e.salary/365) as required_sum from linkedin_projects p JOIN…
Rus Pylypyuk
  • 53
  • 1
  • 5
0
votes
1 answer

Postgres: select all records in 95th percentile

I'm trying to query all rows which are in the 95th percentile. Here's what I tried. select id, percentile_cont(0.95) within group (order by usage asc) as percentile_95 from ResourceUsage where usage > percentile_95
amilajack
  • 127
  • 1
  • 10
0
votes
2 answers

postgres alias sum

I'm trying to run a query that structured something like the following in Postgres, But I'm getting and issue with the column sum(). The query doesn't recognize the price alias. How do I achieve this? select col1, i2f(....) as col2, …
TheMan68
  • 1,429
  • 6
  • 26
  • 48
0
votes
1 answer

Why extra subquery needed for filtering out where clause?

First of all. Sorry for the vague title. I couldn't figure out how to frame it. With the sample code, I hope you can understand my doubt. The task was to find out the top three facilities in a club in terms of revenue generated. I thought this is…
Tapan Das
  • 21
  • 5
0
votes
1 answer

Why do I get an error querying from column alias?

I'm getting an error querying from the column alias and don't understand why. In the example below, if I run a query from the actual column, no problem. I concatenate first_name and last_name columns into a fullname column alias and then get the…
Robin Sage
  • 969
  • 1
  • 8
  • 24
0
votes
1 answer

Syntax Error when using a case when conditional

I am getting the following error: postgresql error: syntax error at or near "2020" LINE 2: ... THEN amount * split_exchange_rate ELSE 0 END) AS 2020Q4_rev... See code below. I am using postgresql SELECT object_id , SUM(CASE WHEN created::date >=…
0
votes
1 answer

Postgres - Use aliased column in subquery

Is it possible to take an aliased column from the outer query and use it to filter a subquery. In essential, I'd like to do something like this select distinct array_agg(foo.id) as foo_list, (select sum(data) from foo where id in…
Mcscrag
  • 55
  • 6
0
votes
1 answer

how to sum in Postgres

I have the data I'm querying total_a | total_b | sum | 1200 500 ? this my query select ROUND(SUM(CASE WHEN status= 0 THEN total_budget ELSE 0 END)) AS total_a, ROUND(SUM(CASE WHEN status= 1 THEN total_sisa_tahun_lalu ELSE 0…
Jon
  • 109
  • 2
  • 10
0
votes
2 answers

How to reuse column alias in another column within same select statement?

select pd.id ,[value 1] = Case ---- End ,[value 2] = Case when [value 1] in ('test1', 'test2') Then 0 else [value 1] End I am getting as invalid column when I try to use…
Box
  • 113
  • 12
0
votes
1 answer

Msg 207, Level 16, State 1, Line 1 Invalid column name 'ItemTotal'

I wrote this code. It works fine without my WHERE Statement. I keep getting an error Msg 207, Level 16, State 1, Line 1 Invalid column name 'ItemTotal'. I don't know what I did wrong! SELECT         ItemID,      ItemPrice,         ItemPrice *…
0
votes
1 answer

Column doesn't exist when using WITH statement PostgreSQL

I want to create a function to be used to get the node traversal path. CREATE TYPE IDType AS (id uuid); drop function F_ItemPath; CREATE OR REPLACE FUNCTION F_ItemPath (item record) RETURNS TABLE (item_id uuid, depth numeric) AS $$ BEGIN return…
muazhari
  • 77
  • 5
0
votes
1 answer

ORA-00923: FROM keyword not found where expected, parameters in AS clause

SELECT LMD0011M.CKEY1 AS CDNAME ,LMD0011M.CKEY1 || '\:' || LMD0011M.CDTA1 AS NMNAME FROM LMD0011M LMD0011M The above query works fine but when I change the column names to parameters... I get an…
0
votes
1 answer

SELECT AS column does not exist in WHERE clause

I am using Postgres to select values from a relation in my database. I would like to have additional columns that do not exist in the original relation, so I achieve this using a query similar to the one below: SELECT table1.*, table1.title ||…
user14131782
  • 736
  • 1
  • 11
  • 20