Page 1 of 1
How to count the number of unique values in a column?
Posted: Fri May 01, 2015 1:55 pm
by Eugene Lutsenko
How to quickly count the number of unique values in a database column?
Code: Select all
INDEX ON FIELDGET(ff) TO Mrk_funi UNIQUE
Re: How to count the number of unique values in a column?
Posted: Fri May 01, 2015 6:34 pm
by Auge_Ohr
Eugene Lutsenko wrote:How to quickly count the number of unique values in a database column?
Code: Select all
INDEX ON FIELDGET(ff) TO Mrk_funi UNIQUE
try this
Code: Select all
*- the following translation is for column total summaries
#xtranslate TOTAL(<field>,<cond>) => ;
{ || TOTALFOOTER( { || < field > }, { || < cond > } ) }
/*------------------------------------------------------------------------
TOTALFOOTER()
Total the column and return result as a string.
SYNTAX: TotalFooter(expB1, expB2, expC1)
<expB1> - code block containing column expression to total
<expB2> - code block while condition
<expC1> - filter expression
RETURNS: String value of total
--------------------------------------------------------------------------*/
FUNCTION TOTALFOOTER( bExpr, bFor )
LOCAL nSaveRec
LOCAL nTotal := 0
nSaveRec := RECNO()
DBGOTOP()
DBEVAL( { || nTotal := nTotal + EVAL( bExpr ) }, { || EVAL( bFor ) },,,, .T. )
DBGOTO( nSaveRec )
RETURN LTRIM( STR( nTotal ) )
Re: How to count the number of unique values in a column?
Posted: Sat May 02, 2015 9:37 pm
by Eugene Lutsenko
COUNT TO
Re: How to count the number of unique values in a column?
Posted: Sun May 03, 2015 12:08 pm
by Auge_Ohr
Eugene Lutsenko wrote:COUNT TO
so i misunderstood what you want to do...
Re: How to count the number of unique values in a column?
Posted: Sun May 03, 2015 1:06 pm
by Eugene Lutsenko
Auge_Ohr wrote:Eugene Lutsenko wrote:COUNT TO
so i misunderstood what you want to do...
Excuse me. This is due to the fact that I use machine translation into English
Re: How to count the number of unique values in a column?
Posted: Thu May 07, 2015 12:51 am
by Tom
Be aware of that a UNIQUE indexed record that is being removed does NOT automatically cause the maybe following record with the same data to be inside the index! If you have an unique index on "NAME" on a table like this:
NAME NO
Miller 1
Harper 2
Miller 3
"Miller 1" will be in the unique index. If you delete "Miller 1", "Miller 3" will NOT be in the index - you will find nothing when searching "Miller" then. This will only happen if you a) create the index again or b) replace the name of "Miller 3" with "Miller".