mysql - Django raw() query, calculated field in WHERE clause -


I am thinking that there are no limitations on syntax of raw () method when using calculated areas. Here's a quick example:

  company.objects.raw (select 'Core_space.ro as core_location.b, core_company' '' 'by command)   

The above code works as expected (the result count fields are sorted by 'dist'), but when I add the WHERE clause, for example:

  company. Objects. Draw ("Select, Core_Law Cation. A + Core_Location.B is distributed as Core, Core_Company where Dell & # 39; 10 & # 39; by Order & # 39; & # 39; & # 39; & # 39; Order by & # 39; & # 39;   

(1054, "section" in "unknown column").

So far it seems that I can not use the calculated field in the WHERE section, but I want to call it ORDER BY statement. Please share your experience thanks.

It's actually with DjangoDo not do anything, but the way MySQL works.

You can not use aliases in WHERE situations, because the algorithm evaluation is evaluated before the alias evaluation.

  • Repeat the segment:

      Company.objects.raw ('' 'SELECT *, Core_location.a + core_location Distributed from Core_location as .b, core_company WHERE (core_location.a + core_location.b) & lt; 10; '' '' by the order 10)    
  • One Substitulate:

      company.obies dot (select 'from * select (select, Core_space Core_space as core, core_company), sub-selection WHERE dist & lt; 10 '' '' by order)      

Comments