Questions tagged [column-alias]

155 questions
1
vote
1 answer

MYSQL - calculated column aliases?

I want to have a SELECT statement name columns based on other column values. Let's say I have a table with column names like q_1, q_2 and other columns like q_1_name and q_2_name Right now we are doing something like SELECT SUM(q_1), SUM(q_2) from…
Pól
  • 140
  • 11
1
vote
1 answer

MySQL, Aggregate SubSelect Problem

I'm in the process of developing a site that will allow players of a certain game to upload their levels and tag them. Each player's account is actually an account in the forums that the site is using (SMF). I am able to return all tags associated…
user274549
1
vote
0 answers

How can I use column alias in later part of a hive query

Is there a way to use column alias declared earlier later in the query? I have something like this select item_id, sum(sales) as total_sales, sum(cost) as total_cost total_sales - total_cost as total_profit from table A …
Manoj Agrawal
  • 775
  • 3
  • 8
  • 20
1
vote
1 answer

Median with Postgres 9.4 - Why isn't my code working?

SELECT (users.created_at::timestamp - invitations.created_at::timestamp) as elapsed, percentile_disc(0.50) WITHIN GROUP (ORDER BY elapsed) as median FROM invitations join users on users.id = invitations.user_id Trying to find out the…
JasonGenX
  • 4,952
  • 27
  • 106
  • 198
1
vote
1 answer

PostgreSQL: Window functions using column alias

I have a following table : Table "public.activity" Column | Type | Modifiers …
hemantvsn
  • 1,316
  • 3
  • 12
  • 24
1
vote
1 answer

to_char(Column_name) what would be the column name in dataset

I have a column name as CREATEDATE. I use this sqlcommand to get the information string sql = "SELECT USERID,USERNAME,USERPOSITION,UPDATEUSERID,USERSTATUS,TO_CHAR(CREATEDATE, 'DD-MM-YYYY HH24:MI:SS') FROM USERMASTER WHERE USERID ='" + stat[0] +…
Lst Patrick
  • 123
  • 6
  • 19
1
vote
2 answers

sql alias field

in SQL, supposes I need to refer to an aliased field in the having clause but the alias has quotes, how do I do that? select (select...) as '005' group by ... having '005'>0
user157195
1
vote
1 answer

How to add multiple names to attribute or columns in MySQL database table

I have a database named Football with a table named Club. My team columns are club_name, location, manager and established. I need to know, how to add two or more names to same column. Like for example, in order to find location, I can type city…
Swanand Pangam
  • 858
  • 1
  • 10
  • 25
1
vote
3 answers

Using alias name in WHERE clause

I am executing the below query and using alias name for all columns. I have named alias with a . since that is a requirement. now, I want to refer to the alias name directly in the where clause and i do is as given below: SELECT pt.prod_desc…
Ankit
  • 129
  • 7
  • 17
1
vote
1 answer

How to add a column alias into yii active record model?

In my old project I used long id for table primary key, like 'shop_id' or 'order_id', but now I want to use just 'id' as alias for 'shop_id'. How to add this to the model class only, not changing tables. After that I'd like to have something like…
Alex Shwarc
  • 822
  • 10
  • 20
0
votes
1 answer

Using Column Alias in WHERE clause in SQL, getting 'Unrecognized Name' Error. What's the workaround?

I have put COUNT(*) AS num_of_trips in the SELECT Clause. Now, I want to use num_of_trips > 30 in WHERE Clause but it gives "unrecognized name" error. I also tried to workaround it by putting the same argument in WHERE clause…
0
votes
2 answers

Is it possible to label group conditions in postgres?

example pseudo-sql SELECT *, condlabel FROM tbl WHERE cond1:(col1 = 1) OR cond2:(col2 = 2 and col3 = 4) so the results will have additional column with exact condition label which they are satisfy
Abyss
  • 315
  • 2
  • 11
0
votes
1 answer

Alias Name in Postgresql with value from select statement

I am performing a select query to select time-series values. I select the column with the timestamp and the column with a measured value from two sub-queries that contain the relevant data. SELECT t1.measured_value as value, t2.time FROM ( …
DerWolferl
  • 71
  • 7
0
votes
1 answer

ERROR in name of column created from Conditional in a query for SUM POSTGRES

I am trying to get employees total by department but I have the next error in my query SELECT d.id_departaments, SUM(d.num_employees) AS "TOTAL" FROM employees e, departamentos d WHERE e.id_departament = d.id_departament AND "TOTAL" > 100 GROUP…
0
votes
2 answers

Unable to access column alias in WHERE clause

I am trying to filter rows from my Postgres database with below query. Everything works fine but when I try to check if latesttask column is null or has some value then it shows error: error: column "latesttask" does not exist SELECT *, ( …
Drashti Kheni
  • 1,065
  • 9
  • 23