Re: cross tab needs in SQL
Posted in 2006
bozon — — source: Usenet: comp.databases.informix
This perl program should do the trick and it should be fast: Of course substitute your path to perl after #! on first line. From vi I always r! which perl . You call it like crosstab.pl <filename> #!/usr/bin/perl -w use strict; my %htCols ; my %htData ; my( $id, $days, $count); while (<>) { chomp; ($id, $days, $count) = split /\\|/ ; $htCols{ $days } = 1 ; $htData{ $id }{ $days } = $count ; } my @colKeys = sort keys %htCols ; foreach my $id (sort keys %htData) { printf("$id|"); foreach my $col (@colKeys) { if (exists($htData{$id}{$col}) ) { printf("%s|",$htData{$id}{$col}) } else { print "|" ; } } print "\\n" ; }