select other values rather than group by django -


lets take example

orderitem.objects.filter(order=order).values('item')\   .annotate(number_sold= count('item'), amount= sum('total'))  query return me 3 columns item, number_sold, amount.... if add other columns in values added in group clause. 

is there way can select other column , cannot appear in group clause

no. @ sql level, if it's not in group clause need aggregation performed on it. since you're not specifying aggregation occur on it, needs go in group clause if it's supposed returned.

edit:

if consider following table table in database:

cola | colb | colc  1   |    | true  1   |    | false  1   |  b   | true  1   |  b   | false  2   |    | true  2   |    | false  2   |  b   | true  2   |  b   | false 

if want max value cola run select max(cola) table;. return 2.

however, if specify want column colb returned, system needs know how handle them. otherwise doesn't know ones show, since there 4 rows have value 2 cola, have 2 different values colb.

so that's group comes play. if do

select max(cola), colb table group colb; 

it return:

max | colb   2 |   2 | b 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -