Hello !
I create this topic, because I have a question concerning the COUNT(My field) OVER (PARTITION BY My Other Field) and the DISTINCT statement.
Here is the situation : I have in one table the following lines :
Name;Hair Colour;Timestamp
Ted;brown;t1
Ted;red;t2
Ted;brown;t3
Ted;blue;t4
Ben;blond;t5
Ben;green;t6
Ben;purple;t7
Ben;green;t8
I would like to obtain the following result :
Name;colour;Total Nb of distinct hair colours per name
Ted;brown;3
Ted;red;3
Ted;blue;3
Ben;blond;3
Ben;green;3
Ben;purple;3
I tried this :
SELECT
name
, hair_colour
, COUNT(hair_colour) OVER (PARTITION BY name)
FROM
MyTable;
But it gives me the following result :
Name;colour;Total Nb of distinct hair colours per name
Ted;brown;4
Ted;red;4
Ted;blue;4
Ben;blond;4
Ben;green;4
Ben;purple;4
I think maybe it could be a good idea to use of DISTINCT in the count over, but unfortunately, this is not permitted.
I'm new in Teradata, so I just hope this question does not look completely stupid :D.
Best regards.
Gwen
Forums: