|
|
|
|
| |
}
if (n == 0)
printf ("No observations\n");
else
{
printf ("Number of observations: %lu\n", n);
printf ("Missing observations: %lu\n", missing);
printf ("Sum: %g\n", sum);
printf ("Mean: %g\n", sum / n);
printf ("Sum of squares: %g\n", sum_squares);
var = ((n * sum_squares) - (sum * sum)) / (n * (n - 1));
printf ("Variance: %g\n", var);
printf ("Standard deviation: %g\n", sqrt (var));
}
}
Note the call to mysql_data_seek() that precedes the mysql_fetch_row() loop. It positions to the first row of the result set, which is useful in case you want to call summary_stats() multiple times for the same result set (for example, to calculate statistics on several different columns). The effect is that each time summary_stats() is invoked, it "rewinds" to the beginning of the result set. The use of mysql_data_seek() requires that you create the result set with mysql_store_result(). If you create it with mysql_use_result(), you can only process rows in order, and you can process them only once.
summary_stats() is a relatively simple function, but it should give you an idea of how you could program more complex calculations, such as a least-squares regression on two columns or standard statistics such as a t-test or an analysis of variance.
Encoding Problematic Data in Queries
If inserted literally into a query, data values containing quotes, nulls, or backslashes can cause problems when you try to execute the query. The following discussion describes the nature of the difficulty and how to solve it.
Suppose you want to construct a SELECT query based on the contents of the null-terminated string pointed to by the name_val variable:
|
|
|
|
|
|
| Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist |
|