Page 1 of 1
GROUP BY bug
Posted: Thu May 27, 2010 2:15 pm
by katoussa
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.
Please help me how to do this translate on Rel.
Re: GROUP BY bug
Posted: Thu May 27, 2010 9:45 pm
by dao
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?
Re: GROUP BY bug
Posted: Fri May 28, 2010 7:00 am
by Dave
In
Tutorial D, the equivalent to GROUP BY is either GROUP or SUMMARIZE.
GROUP is used to create nested relations. E.g.:
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:
Re: GROUP BY bug
Posted: Fri May 28, 2010 8:28 pm
by dao
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?
Re: GROUP BY bug
Posted: Fri May 28, 2010 9:02 pm
by Dave
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)