[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] Displaying Percentages
Quoting Jim Webster (jim@powergatenetworks.com):
> Using MySQL, is it possible to compare the value of a field and display a
> percentage?
>
> I'd like to say something like:
>
> "84% of our products are in the XYZ category"
>
> The tag: [value-extended mv_search_match_count] obviously produces the # in
> the category.. maybe I can convert this to a percentage?
You can do it in a query, of course, using SQL.
In a search-list, you would need to display all of the items with a ml=9999
or somesuch.
Then:
[search-region]
[search-list]
[item-calc]
$all++;
$total{'[item-field category]'}++;
return;
[/item-calc]
[/search-list]
[on-match]
[calc]
my @out;
for (keys %total) {
my $pct = $total{$_} / $all * 100;
push @out, sprintf("%.1f%% in category %s", $pct, $_);
}
return join ", ", @out;
[/calc]
[/on-match]
[/search-region]
--
Red Hat, Inc., 3005 Nichols Rd., Hamilton, OH 45013
phone +1.513.523.7621 <mheins@redhat.com>
Few blame themselves until they have exhausted all other possibilities.
-- anonymous