File: 0.04.06a/server/bin/clearbigrecords.sh (View as HTML)

  1: #!/usr/bin/php -q
  2: <?php
  3: require("include.php");
  4: $NATS->Start();
  5: 
  6: $q="SELECT testid,AVG(testvalue) FROM fnrecord GROUP BY testid";
  7: $r=$NATS->DB->Query($q);
  8: 
  9: echo $q."\n";
 10: 
 11: while ($row=$NATS->DB->Fetch_Array($r))
 12: {
 13: $limit=100*$row['AVG(testvalue)'];
 14: if ($limit>1)
 15: 	{	
 16: 	$q="DELETE FROM fnrecord WHERE testid=\"".$row['testid']."\" AND testvalue>".$limit;
 17: 	$NATS->DB->Query($q);
 18: 	echo $row['testid']." - deleted ".$NATS->DB->Affected_Rows()."\n";
 19: 	}
 20: }
 21: 
 22: $NATS->Stop();
 23: 
 24: ?>
 25: 
 26: