bazz
02-09-2008, 03:11 PM
ok, I am querying a table where there are three cols. I need the distinct values from each column, relative to the preceding one.
code so far:
my $sth = $dbh->prepare ("SELECT COUNT(DISTINCT Business_Type),COUNT(DISTINCT Business_Sub_Type),COUNT(DISTINCT Business_Category)
FROM $table BT
WHERE Business_Type = '$parameter'
ORDER BY Business_Type,Business_Sub_Type,Business_Category
") or die "prepare statement failed: $DBO::errstr\n";
my $rc = $sth->execute
or die "Can't execute statement: $DBI::errstr";
This gives me the total number of distinct values in each field however, I need to retrieve the total number of distinct values in col2, for each distinct value in col 1. likewise for col 3, I need the number of distinct values from col3, for each of col 2 and col1's distinct values.
do I need to start building sub queries or what is the appropriate step forward.
bazz
code so far:
my $sth = $dbh->prepare ("SELECT COUNT(DISTINCT Business_Type),COUNT(DISTINCT Business_Sub_Type),COUNT(DISTINCT Business_Category)
FROM $table BT
WHERE Business_Type = '$parameter'
ORDER BY Business_Type,Business_Sub_Type,Business_Category
") or die "prepare statement failed: $DBO::errstr\n";
my $rc = $sth->execute
or die "Can't execute statement: $DBI::errstr";
This gives me the total number of distinct values in each field however, I need to retrieve the total number of distinct values in col2, for each distinct value in col 1. likewise for col 3, I need the number of distinct values from col3, for each of col 2 and col1's distinct values.
do I need to start building sub queries or what is the appropriate step forward.
bazz