#29976 closed Uncategorized (invalid)
How to perform Group by on Union of two models
Reported by: | Sandeep | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.1 |
Severity: | Normal | Keywords: | Union and annotate(Count('')) |
Cc: | k.sandeep44@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I have two models like this:
class Story(models.Model): name = models.TextField(db_column='NAME') # Field name made lowercase. status = models.TextField(db_column='STATUS') # Field name made lowercase. class Bug(models.Model): name = models.TextField(db_column='NAME') # Field name made lowercase. status = models.TextField(db_column='STATUS') # Field name made lowercase.
I would like to get count of Unique status from above two tables
Query: Select new_table.status, Count(new_table.name) from (select status, name from Story Union select status, name from Bug) new_table group by new_table.status
Change History (3)
comment:1 by , 6 years ago
Severity: | Release blocker → Normal |
---|
comment:2 by , 6 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 6 years ago
Description: | modified (diff) |
---|
Note:
See TracTickets
for help on using tickets.
The Release Blocker status is for data loss bugs and regressions from previous versions of Django. As far as I can see this isn't that.
There's no bug report here. Please see TicketClosingReasons/UseSupportChannels for help.