On 06/02/2010, at 10:07 PM, personalt wrote:

> I am just looking to pass a value from one query into a second.  Is
> that possible?  Can I modify the query below to get the two queries to work
> together so that the .19 is repalce by the kwhcost1 from the first query?
> 
> select kwhcost1 from applications;
> 
> SELECT monitordata_hourly.deviceaddress,
> Round(Sum(monitordata_hourly.ch1kwh),3) AS SumOfch1kwh,
> Round(Sum(monitordata_hourly.ch1kwh),3)*.19 AS SumOfch1kwh_cost
> FROM monitordata_hourly
> Where monitordata_hourly.deviceaddress=142265 and
> (datetime(monitordata_hourly.date))>=datetime('now', 'localtime', '-30
> days')
> Group by monitordata_hourly.deviceaddress

Simply enter your first query as a "subquery" in the second, like this:

SELECT monitordata_hourly.deviceaddress,
Round(Sum(monitordata_hourly.ch1kwh),3) AS SumOfch1kwh,
Round(Sum(monitordata_hourly.ch1kwh),3)*(select kwhcost1 from applications) AS 
SumOfch1kwh_cost
FROM monitordata_hourly
Where monitordata_hourly.deviceaddress=142265 and
(datetime(monitordata_hourly.date))>=datetime('now', 'localtime', '-30
days')
Group by monitordata_hourly.deviceaddress

Tom
BareFeet

 --
Comparison of SQLite GUI tools:
http://www.tandb.com.au/sqlite/compare/?ml

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to