## GROUP BY bug

This forum is for any questions about the language Tutorial D or the Rel implementation of it.
katoussa
Posts:11
Joined:Wed May 05, 2010 10:24 pm
GROUP BY bug
Hi,

I want to do the translate for this code:

Select Count (d1.id_personne), d2.id_personne
FROM deplacement d1, deplacement d2
GROUP BY d2.id_personne

With tutorial D I can use SUMMARIZE TO HAVE THE RESULT OF GROUP BY but with summarize Rel don't accept parameters in COUT ON THE SUMMARIZE SYNTAX.

Is that a Rel failure or Rel offers an alternative.

dao
Posts:2
Joined:Thu May 27, 2010 9:34 pm

### Re: GROUP BY bug

Me too I have some trouble with the use of group by with tutorial d.

Is it possible to define group by in Rel? If yes, then what is the correct syntax?

Dave
Posts:368
Joined:Sun Nov 27, 2005 7:19 pm

### Re: GROUP BY bug

In Tutorial D, the equivalent to GROUP BY is either GROUP or SUMMARIZE.

GROUP is used to create nested relations. E.g.:

Code: Select all

``myvar1 GROUP ({x} AS r)``
SUMMARIZE is closer to SQL's 'GROUP BY'.

When using COUNT in SUMMARIZE, there is no reason why COUNT would have a parameter, because the COUNT of any attribute is the same for all attributes.

Here's an example of using COUNT in SUMMARIZE:

Code: Select all

``SUMMARIZE myvar1 BY {x} ADD (COUNT() AS n)``
It assumes the following relvar:

Code: Select all

``````VAR myvar1 REAL RELATION {x INTEGER, y INTEGER} KEY {x, y};
myvar1 := RELATION {
TUPLE {x 1, y 1},
TUPLE {x 1, y 2},
TUPLE {x 2, y 2},
TUPLE {x 2, y 4},
TUPLE {x 3, y 5}
};``````
There is also a COUNT() operator that returns the cardinality of a relational expression. For example:

Code: Select all

``COUNT(myvar1)``

dao
Posts:2
Joined:Thu May 27, 2010 9:34 pm

### Re: GROUP BY bug

When using COUNT in SUMMARIZE, there is no reason why COUNT would have a parameter, because the COUNT of any attribute is the same for all attributes.

Here's an example of using COUNT in SUMMARIZE:
[code]SUMMARIZE myvar1 BY {x} ADD (COUNT() AS n)[/code]

CAN I USE WHERE WITH SUMMARIZE?

Dave
Posts:368
Joined:Sun Nov 27, 2005 7:19 pm

### Re: GROUP BY bug

dao wrote:When using COUNT in SUMMARIZE, there is no reason why COUNT would have a parameter, because the COUNT of any attribute is the same for all attributes.

Here's an example of using COUNT in SUMMARIZE:

Code: Select all

``SUMMARIZE myvar1 BY {x} ADD (COUNT() AS n)``
CAN I USE WHERE WITH SUMMARIZE?
Sure. You can do this:

Code: Select all

``SUMMARIZE (myvar1 WHERE x=2 AND y=3) BY {x} ADD (COUNT() AS n)``