Create name for additional column in query

34 views
Skip to first unread message

Константин Комков

unread,
Oct 15, 2019, 7:53:33 AM10/15/19
to web2py-users
I have that query:
sumAuditorHours = db.a_wlp2_distrib.LC_HOURS + db.a_wlp2_distrib.SM_HOURS + db.a_wlp2_distrib.LB_HOURS
subjects = db((db.a_groups.id == group) & (db.a_wlp2_distrib.MODULE == module) & (db.a_wlp2.PARENT_ITEM != None)).select(db.s_disc_names.id,db.s_disc_names.FULL_NAME,db.a_wlp2.CHAIR,sumAuditorHours,orderby=db.s_disc_names.FULL_NAME,
    join=[db.a_wlp2.on(db.a_groups.WLP == db.a_wlp2.WLP),
    db.a_wlp2_distrib.on(db.a_wlp2.id == db.a_wlp2_distrib.WLP_ITEM),
    db.s_disc_names.on(db.a_wlp2.DISC_NAME == db.s_disc_names.id)]
)
db._lastsql looks like:
SELECT s_disc_names.id, s_disc_names.FULL_NAME, a_wlp2.CHAIR, ((a_wlp2_distrib.LC_HOURS + a_wlp2_distrib.SM_HOURS) + a_wlp2_distrib.LB_HOURS)
FROM a_groups
JOIN a_wlp2 ON (a_groups.WLP = a_wlp2.WLP)
JOIN a_wlp2_distrib ON (a_wlp2.id = a_wlp2_distrib.WLP_ITEM)
JOIN s_disc_names ON (a_wlp2.DISC_NAME = s_disc_names.id)
WHERE (((a_groups.id = 2277) AND (a_wlp2_distrib.MODULE = 3)) AND (a_wlp2.PARENT_ITEM IS NOT NULL)) ORDER BY s_disc_names.FULL_NAME
How can I add as my_column_name?
Now rows looks like on picture.

Thank you.



1.png

Massimiliano

unread,
Oct 15, 2019, 9:00:59 AM10/15/19
to web...@googlegroups.com
fields = [db.s_disc_names.id.with_alias('id'),
          db.s_disc_names.FULL_NAME-with_alias('full_name'),
          db.a_wlp2.CHAIR.with_alias('chair')
         ]
subjects = db((db.a_groups.id == group) & (db.a_wlp2_distrib.MODULE == module) & (db.a_wlp2.PARENT_ITEM != None)).select(*fields, ...



--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/871e5991-8ddb-4c85-a1a9-72accc1c5aba%40googlegroups.com.


--
Massimiliano

Massimiliano

unread,
Oct 15, 2019, 11:04:40 AM10/15/19
to web...@googlegroups.com
Sorry I miss a piece:

sumAuditorHours = (db.a_wlp2_distrib.LC_HOURS + db.a_wlp2_distrib.SM_HOURS + db.a_wlp2_distrib.LB_HOURS)
fields = [db.s_disc_names.id.with_alias('id'),
          db.s_disc_names.FULL_NAME-with_alias('full_name'),
          db.a_wlp2.CHAIR.with_alias('chair'),
          sumAuditorHours.with_alias('auditor_hours'),
         ]
subjects = db((db.a_groups.id == group) & (db.a_wlp2_distrib.MODULE == module) & (db.a_wlp2.PARENT_ITEM != None)).select(*fields, ...
--
Massimiliano

Константин Комков

unread,
Oct 15, 2019, 1:16:05 PM10/15/19
to web...@googlegroups.com
No problem, I understand that I need to use with_alias('my_column_name'). Thank you! 

вт, 15 окт. 2019 г., 18:04 Massimiliano <mbel...@gmail.com>:
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/GiDioBnqHts/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/CANPTPxKc8HqS7JsU%2ByzB8FN4%2BDV7Oz8%3DR6DET98H-mD8xDojew%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages