I read and tried every post I could find, also tried to add the patch from http://drupal.org/node/695298#comment-4905348 but I'm still at a dead end.
I'm using
Drupal 6.22
Views 6.x-3.0-alpha3
CCK 6.x-2.9

I set up a Content Type (Entry) with several fields, among them one (Number) is an integer and another one (Type) is a varchar
I made a View with
Style: Table
Use Grouping: Yes
Fields: Number (SUM), Type
Filter: Type is "Entry"

I was hoping for a single row for each distinct Type with Number being the sum of all the rows but I still get all the rows distinct

In the query i can see there are node_type, nid, node_vid, node_created in the Group By statement and no matter what I do I always get them, what I'm doing wrong?

CommentFileSizeAuthor
#6 pic01.png55.1 KBkeyiyek
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Please fill out the data probably. You currently saying it.s 2.9 even you are using the views groupby feature.

keyiyek’s picture

Version: 6.x-2.9 » 6.x-3.0-alpha3

Sorry, my mistake, after two days applying avery patch to CCK 2.9 I lost track of what I was actually doing...

still the problem remains

dawehner’s picture

Nid shouldn't be part of the query. Could it be that some of the fields are linked to it's node?

keyiyek’s picture

ok, I get rid of the nid and date,
date was coming from the sorting setting (nid I don't know but is gone)
manually applied the patch from the post quoted in #1
but still have issues

I have only
2 fields set: Content:Number and Content:Type
1 Filter: Node:Type

I set Content:Number as SUM but I see that in the query the Group By statement has both Content:Number and Content:Type, so the Number is summed only if both Type and Number are the same

dawehner’s picture

In general you can have something either in the groupby part of the query or be part of an aggregation function like SUM or COUNT.

To be able to use it please update to the 6.x-3.x-dev and to the latest cck version as well, older versions aren't supported because they are old :)

keyiyek’s picture

FileSize
55.1 KB

thanks for the time you are taking to answer me but I still can't make it working.
I updated everything to the latest revision. For what I understand from this post http://drupal.org/node/695298
a patch to cck must be applied, did that also.
Now if I set something like picture 01
the resulting query is

SELECT SUM(node_data_field_ball_num.field_ball_num_value)
AS node_data_field_ball_num_field_ball_num_value, node_data_field_ball_num.field_ball_num_value
AS node_data_field_ball_num_field_ball_num_value_1
FROM node node 
LEFT JOIN content_field_ball_num node_data_field_ball_num
ON node.vid = node_data_field_ball_num.vid
WHERE node.type in ('', '', '', 'ingresso')
GROUP BY node_data_field_ball_num_field_ball_num_value_1

as you see I still get in the group by the field I am summing on, this means I can sum rows where the number is the same

dawehner’s picture

Mh you might have to update to 6.x-3.x-dev as well.

Please try to use the dev version of views and somehow latest with the patch of cck. This should really work from my perspective.

keyiyek’s picture

Version: 6.x-3.0-alpha3 » 6.x-3.x-dev

still no luck
I still have a field both in the SUM and the GROUP BY statement

is there any way I can manually change the query? Not a perfect solution, but good enough to make me able to deliver the final product

keyiyek’s picture

Some news on this issue

I was following step by step the code to understand what was going on and I stepped into something I don't understand
this is the query up to now

SELECT node_data_field_tipo.field_tipo_nid
    AS node_data_field_tipo_field_tipo_nid,
  MAX(node.nid)
    AS nid, node_data_field_luogo.field_luogo_nid
    AS node_data_field_luogo_field_luogo_nid,
  SUM(node_data_field_ball_num.field_ball_num_value)
    AS node_data_field_ball_num_field_ball_num_value, node_data_field_ball_num.field_ball_num_value
    AS node_data_field_ball_num_field_ball_num_value_1
    FROM node node
      LEFT JOIN content_field_tipo node_data_field_tipo
        ON node.vid = node_data_field_tipo.vid
      LEFT JOIN content_type_ingresso node_data_field_luogo
        ON node.vid = node_data_field_luogo.vid
      LEFT JOIN content_field_ball_num node_data_field_ball_num
        ON node.vid = node_data_field_ball_num.vid
    WHERE node.type in ('ingresso')
    GROUP BY node_data_field_tipo_field_tipo_nid, node_data_field_luogo_field_luogo_nid, node_data_field_ball_num_field_ball_num_value_1

a "node_data_field_ball_num_field_ball_num_value_1" is present that actually should not exist.
It is created by the following line

        $handlers[$id]->query($this->display_handler->use_group_by());

in view.inc file
this line is run for each field: nid, tipo, luogo, ball_num. Every other field returns a single object placed in query[fields], but ball_num, that returns 2 objects ball_num and ball_num_1.

I'm pretty sure that is the problem, since ball_num_1 should be not there.

Anyone with some sugestions

keyiyek’s picture

Title: Grouping » [SOLVED] Grouping

ok, found out what the problem was and found a fix

I went deeper in the code and found out the alias_01 was created in views_plugin_query_default.inc around the end of function add_field (about line 700). The problem was that the function is called twice for each field (don't ask me why), and in the said function there is a check whether the second time the field is the same, but according to the $field_info variable the second time there is no reference to the aggregation function so the fields are seen as different and the alias_01 pops out.

thanks to an hint here http://drupal.org/node/695298#comment-4917872, which at first I supposed not relevant, I applied the patch here
http://drupal.org/node/1073350#comment-4350016 and now things seem to work smoothly.

In the end I'm working with CCK 6.x-2.8 and Views 6.x-3.x-dev

dawehner’s picture

Status: Active » Fixed

If you found a solution to an issue feel free to mark the issue as fixed next time.

keyiyek’s picture

Sorry, changed the title forgot to change the status

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.