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.
GROUP BY bug
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?
Is it possible to define group by in Rel? If yes, then what is the correct syntax?
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.:
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:
It assumes the following relvar:
There is also a COUNT() operator that returns the cardinality of a relational expression. For example:
GROUP is used to create nested relations. E.g.:
Code: Select all
myvar1 GROUP ({x} AS r)
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)
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}
};
Code: Select all
COUNT(myvar1)
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?
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
Sure. You can do this: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:CAN I USE WHERE WITH SUMMARIZE?Code: Select all
SUMMARIZE myvar1 BY {x} ADD (COUNT() AS n)
Code: Select all
SUMMARIZE (myvar1 WHERE x=2 AND y=3) BY {x} ADD (COUNT() AS n)