How to run direct sql


#1

How can i run and get the value from the following sql:

select avg(my_field) from my_table where which_year=‘0506’ and
which_week <= 21 and my_foreign_key_id=10

cheers


#2

thanks!


#3

On 1/16/06, chris hulbert removed_email_address@domain.invalid wrote:

How can i run and get the value from the following sql:

select avg(my_field) from my_table where which_year=‘0506’ and
which_week <= 21 and my_foreign_key_id=10

You can use:
YourModel.connection.select_value(your_query_string)
…which returns the result as a string that you will need to type_cast
into whatever you need.

If you find yourself doing a lot of this, you should look at the cool
Calculations plugin:
http://techno-weenie.net/svn/projects/plugins/calculations/