sql - How to select an "AS field" in MySql? -


i have query separated in different parts. (distance, score , rank)

select entry.*, address.*,  (6367.41 * sqrt(2 * (1-cos(radians(entry.latitude)) * cos(0.92640848333131) * (sin(radians(entry.longitude)) * sin(0.15361853481704) + cos(radians(entry.longitude)) * cos(0.15361853481704)) - sin(radians(entry.latitude)) * sin(0.92640848333131))))  distance,   (case when `entry`.`title` '%%' 50 else 0 end +  case when `entry`.`description` '%%' 30 else 0 end +  case when `entry`.`description_long` '%%' 10 else 0 end +  case when `entry`.`product_type` = 1 0 else 0 end +  case when `entry`.`product_type` = 2 40 else 0 end +  case when `entry`.`product_type` = 3 50 else 0 end )  score,   (case when (score > 100 , distance <= 10) 1 else 0 end)  rank   `usr_web12_1`.`entries` `entry`  inner join `usr_web12_1`.`entrieslocations` `entrieslocation` on (`entry`.`id` = `entrieslocation`.`entry_id`)  inner join `usr_web12_1`.`addresses` `address` on (`address`.`id` = `entry`.`address_id`)  ((`entry`.`title` '%%') or (`entry`.`description` '%%') or (`entry`.`description_long` '%%') or (`entry`.`meta_keywords` '%%') or (`entry`.`filter_keywords` '%%')) , `entry`.`status` = 1 ,  `entry`.`latitude` between 52.179974594081 , 53.978617805919 , `entry`.`longitude` between 7.3045938084915 , 10.298793591508 , `entrieslocation`.`category_id` = 1  group `entry`.`id`  order `entry`.`product_type` desc  limit 10 

question: rank-part doesn't work "column not found: 1054 unknown column 'score' in 'field list'", how can access dynamic as-field???

same problem distance...

thanks lot!

you can't use aliased column name in select or where clause.

you use later in group by, order by, having clause. see the mysql doc that.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -