I really need help with a query I'm trying to execute in Web2Py DAL
is there a way to use an inline table in the FROM field of a query?
this is my query:
SELECT SUM( HoursWorked / DayHoursSum ) AS DaysWorked
FROM `Tasks_TimeLog` H, (
SELECT TheDate, User_id, SUM( HoursWorked ) AS DayHoursSum
FROM `Tasks_TimeLog`
GROUP BY TheDate, User_id
)S
WHERE H.User_id = S.User_id
AND H.TheDate = S.TheDate
AND Task='2'
GROUP BY Task
this is the inline table in Web2py:
inlineTable=db()._select(db.Tasks_TimeLog.TheDate,db.Tasks_TimeLog.User_id,db.Tasks_TimeLog.HoursWorked.sum(),groupby=db.Tasks_TimeLog.TheDate|
db.Tasks_TimeLog.User_id)
how do I use the inline table in my full query??
rows=db(db.Tasks_TimeLog.Task=='2'.....).select(.....,groupby=db.Tasks_TimeLog.Task)
Thanks to all the helpers!!
--
Thadeus
On Apr 13, 10:20 am, Thadeus Burgess <thade...@thadeusb.com> wrote:
> Interesting, what would be the possibility of adding this as a feature
> to the new dal?
>
> --
> Thadeus
>
However, basing queries off of sub-queries(sub-table) happens a lot in
the ms-access world.
--
Thadeus
> --
> To unsubscribe, reply using "remove me" as the subject.
>
On Apr 13, 1:36 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
> I have no immediate use for it.
>
> However, basing queries off of sub-queries(sub-table) happens a lot in
> the ms-access world.
>
> --
> Thadeus
>
But SubTable can do anything a regular table can do, its information
is just dynamic.
mySubTable = db()._select(db.TasksTimeLog.TheDate,
db.TasksTimeLog.User_id,
db.TaskTimeLog.HoursWorked.sum().with_alias('DaysHoursSum),
orderby=db.TasksTimeLog.TheDate|db.TasksTimeLog.User_id)
db.define_sub_table(mySubTable)
db(Tasks_TimeLog.TheDate ==
db.mySubTable.TheDate)(Tasks_TimeLog.User_id ==
db.mySubTable.User_id)(Tasks_TimeLog.Task ==
'2').select(db.mySubTable.DaysHoursSum, db.Task_TimeLog.HoursWorked)
Well... Its just an idea.
--
Thadeus
On Apr 13, 2:11 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
> it is almost like you need another object, SubTable, which can be
> built from the results of a Set object.
>
> But SubTable can do anything a regular table can do, its information
> is just dynamic.
>
> mySubTable = db()._select(db.TasksTimeLog.TheDate,
> db.TasksTimeLog.User_id,
> db.TaskTimeLog.HoursWorked.sum().with_alias('DaysHoursSum),
> orderby=db.TasksTimeLog.TheDate|db.TasksTimeLog.User_id)
> db.define_sub_table(mySubTable)
>
> db(Tasks_TimeLog.TheDate ==
> db.mySubTable.TheDate)(Tasks_TimeLog.User_id ==
> db.mySubTable.User_id)(Tasks_TimeLog.Task ==
> '2').select(db.mySubTable.DaysHoursSum, db.Task_TimeLog.HoursWorked)
>
> Well... Its just an idea.
>
> --
> Thadeus
>
--
Thadeus
On Apr 14, 12:26 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
> Can you add this to the appropriate TODO list with a link to this group posting?
>
> --
> Thadeus
>