column-alias

MySQL select statement with alias fails with column not found

我是研究僧i 提交于 2019-12-13 04:37:14
问题 Development Environment Reference: Fedora FC18 Tomcat Server 7.0.39 (localhost config) Eclipse Juno Release 2 Mysql-connecor-java Ver. 5.1.26 (jar) Mysql-server Ver. 5.5.32 (jar) The following select statement fails with "column 'depth' not found": "select node.subEntityID, node.lft, node.rgt, (count(parent.subEntityID) - 1) as depth from ENTITY as node, ENTITY as parent where node.lft between parent.lft and parent.rgt group by node.subEntityID order by node.lft"; This select statement

Column alias not recognized in WHERE-statement

百般思念 提交于 2019-12-12 11:25:01
问题 I have a strange 'problem' with one of my created queries. Given the next query: SELECT ID, DistanceFromUtrecht, ( SELECT (MAX(DateUntil) - (ReleaseDays * 60 * 60 * 24)) FROM PricePeriod WHERE PricePeriod.FK_Accommodation = Accommodation.ID ) AS LatestBookableTimestamp FROM Accommodation WHERE LatestBookableTimestamp < UNIX_TIMESTAMP() phpMyAdmin keeps throwing an error about not having a column named 'LatestBookableTimestamp', even allthough I've a column, retreived by a subquery, that alias

Mysterious error when combining lead function, second window function and column alias

一世执手 提交于 2019-12-12 06:00:12
问题 Consider the following query: select corpus_date as alias ,lead(word, 1) over (partition by corpus order by word_count desc) lead ,max(word_count) over (partition by corpus) max_word_count from [publicdata:samples.shakespeare] where corpus='othello' and length(word) > 10 limit 5 This gives me the error message Field 'alias' not found. But alias is only used as an alias in this query. Note also that the error disappears if I comment out either the alias, or the lead function or the min

SQL: What does NULL as ColumnName imply

久未见 提交于 2019-12-04 17:47:54
问题 I understand that AS is used to create an alias. Therefore, it makes sense to have one long name aliased as a shorter one. However, I am seeing a SQL query NULL as ColumnName What does this imply? SELECT *, NULL as aColumn 回答1: Aliasing can be used in a number of ways, not just to shorten a long column name. In this case, your example means you're returning a column that always contains NULL , and it's alias/column name is aColumn . Aliasing can also be used when you're using computed values,

SQL: What does NULL as ColumnName imply

为君一笑 提交于 2019-12-03 12:43:06
I understand that AS is used to create an alias. Therefore, it makes sense to have one long name aliased as a shorter one. However, I am seeing a SQL query NULL as ColumnName What does this imply? SELECT *, NULL as aColumn Aliasing can be used in a number of ways, not just to shorten a long column name. In this case, your example means you're returning a column that always contains NULL , and it's alias/column name is aColumn . Aliasing can also be used when you're using computed values, such as Column1 + Column2 AS Column3 . It means that "aColumn" has only Null values. This column could be

Using alias name in WHERE clause

让人想犯罪 __ 提交于 2019-11-28 14:27:58
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 AS"PROD_DESC", ( CASE WHEN pt.prod_level='2' THEN 'Product' WHEN pt.prod_level='4' THEN 'Sub-Product' WHEN pt.prod_level='5' THEN 'Service' ELSE 'N/A' END) AS"PROD_LEVEL", prod_id AS "PROD_ID", isactive AS "IsActive", updt_usr_sid AS "UPDT_USR_SID", updt_ts AS "UPDT_TS", ( CASE WHEN pt.prod_level='5' THEN parent_prod_id ELSE NULL END) AS ".SUB_PROD_ID", (

Laravel 4 Eloquent Column Alias

戏子无情 提交于 2019-11-28 11:31:34
What i am trying to achieve is in my database i have a table named channel i am using laravel's eloquent class to access these the properties from the table The problem that i am facing is that the table name is column and the column name is channel so when accessing that property looks like this. User::find(1)->channel->channel How can i modify this to say User::find(1)->channel->name We cannot change the table name in the database. Options i have thought of: 1)Create views for tables that need columns changed. Too messy... 2)Use column alias.... laravel documentation...sigh.. no clue how? 3

SQL not recognizing column alias in where clause

て烟熏妆下的殇ゞ 提交于 2019-11-27 15:37:50
I am only a beginner in SQL, but I've come across this annoying error. SQL is having an issue with the WHERE clause of this script: SELECT ITEM_ID, ITEM_PRICE, DISCOUNT_AMOUNT, QUANTITY, (ITEM_PRICE*QUANTITY) AS price_total, (DISCOUNT_AMOUNT*QUANTITY) AS discount_total, ((ITEM_PRICE-DISCOUNT_AMOUNT)*QUANTITY) AS item_total FROM ORDER_ITEMS WHERE item_total > 500 ORDER BY item_total; I am receiving this error: Error starting at line : 1 in command - SELECT ITEM_ID, ITEM_PRICE, DISCOUNT_AMOUNT, QUANTITY, (ITEM_PRICE*QUANTITY) AS price_total, (DISCOUNT_AMOUNT*QUANTITY) AS discount_total, ((ITEM

Why can't I use column aliases in the next SELECT expression?

允我心安 提交于 2019-11-27 09:46:06
Can I modify the next to use the column aliases avg_time and cnt in an expression ROUND(avg_time * cnt, 2) ? SELECT COALESCE(ROUND(stddev_samp(time), 2), 0) as stddev_time, MAX(time) as max_time, ROUND(AVG(time), 2) as avg_time, MIN(time) as min_time, COUNT(path) as cnt, ROUND(avg_time * cnt, 2) as slowdown, path FROM loadtime GROUP BY path ORDER BY avg_time DESC LIMIT 10; It raises the next error: ERROR: column "avg_time" does not exist LINE 7: ROUND(avg_time * cnt, 2) as slowdown, path The next, however, works fine (use primary expressions instead of column aliases: SELECT COALESCE(ROUND

Laravel 4 Eloquent Column Alias

混江龙づ霸主 提交于 2019-11-27 06:16:58
问题 What i am trying to achieve is in my database i have a table named channel i am using laravel's eloquent class to access these the properties from the table The problem that i am facing is that the table name is column and the column name is channel so when accessing that property looks like this. User::find(1)->channel->channel How can i modify this to say User::find(1)->channel->name We cannot change the table name in the database. Options i have thought of: 1)Create views for tables that