Professional Documents
Culture Documents
Problem statement :
To execute SQL queries in order to store and retrieve the data under study in a
database. Sqlite is used for executing the queries.
You can verify if your table has been created successfully using SQLIte
command .tables command
sqlite>.tables
COMPANY DEPARTMENT
1
M.Sc.I.T. Semester I Data Analysis Tools
1. Select clause is a data manipulation command used for retrieving the data
in the desired format from the database objects. The syntax of the various select
clause and its purpose is given below:
Select * from company;
2
M.Sc.I.T. Semester I Data Analysis Tools
2. List down all the records where AGE is greater than or equal to 25 AND
salary is greater than or equal to 65000.00:
SELECT * FROM COMPANY WHERE AGE >= 25 AND SALARY >=65000;
3. List down all the records where AGE is greater than or equal to 25 ORsalary
is greater than or equal to 65000.00:
3
M.Sc.I.T. Semester I Data Analysis Tools
4. list down all the records where AGE is not NULL which means all the
records because none of the record is having AGE equal to NULL:
5. list down all the records where NAME starts with 'Ki', does not matter what
comes after 'Ki'.
6.list down all the records where AGE value is either 25 or 27:
sqlite> SELECT * FROM COMPANY WHERE AGE IN ( 25, 27 );
7.list down all the records where AGE value is neither 25 nor 27:
4
M.Sc.I.T. Semester I Data Analysis Tools
8.list down all the records where AGE value is in BETWEEN 25 AND 27:
9. finds all the records with AGE field having SALARY > 65000
5
M.Sc.I.T. Semester I Data Analysis Tools
b) Order by Clause
BY NAME;
c) Following is the example which would display record for which name count
is less than 2:
6
M.Sc.I.T. Semester I Data Analysis Tools
f) Following is an example which limits the row in the table according to the no
of rows you want to fetch from table:
7
M.Sc.I.T. Semester I Data Analysis Tools
g) Joins
8
M.Sc.I.T. Semester I Data Analysis Tools
9
M.Sc.I.T. Semester I Data Analysis Tools
#include <apop.h>
int main(){
gsl_matrix *m = gsl_matrix_alloc(5,10);
gsl_matrix_set_all(m, 1);
Apop_matrix_row(m, i, one_row);
gsl_vector_scale(one_row, i+1);
Apop_matrix_col(m, i, one_col);
gsl_vector_scale(one_col, i+1);
apop_matrix_show(m);
gsl_matrix_free(m);
10
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./ multiplicationtable.out
11
M.Sc.I.T. Semester I Data Analysis Tools
#include <apop.h>
if (!gp)
if (!gp){
return;
apop_matrix_print(data, .output_pipe=gp);
fflush(gp);
int main(){
apop_db_open("data-climate.db");
12
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./pipeplot.out
13
M.Sc.I.T. Semester I Data Analysis Tools
3B: Query out the month, average, and variance, and plot the data
using errorbars.
Prints to stdout, so pipe the output through Gnuplo
#include <apop.h>
int main(){
apop_db_open("data-climate.db");
apop_data *d = apop_query_to_data("select \
avg(tmp), stddev(tmp) \
apop_matrix_show(d->matrix);
14
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./errorbars.out
15
M.Sc.I.T. Semester I Data Analysis Tools
Continous distributions
1. Normal distribution
2. Lognormal distribution
3. Gamma distribution
4. Exponential distribution
5. Beta distribution
#include <stdio.h>
#include <gsl/gsl_randist.h>
int
main (void)
int i;
double p = 0.6;
float sum=0;
printf("-------------------------------------------------------\n");
sum=sum+k;
printf("%d\t\t%f\t\t%f\n",i,k,sum);
16
M.Sc.I.T. Semester I Data Analysis Tools
printf("\n");
return 0;
To compile type:
To execute type:
./bernoulli.out
17
M.Sc.I.T. Semester I Data Analysis Tools
#include <gsl/gsl_randist.h>
int
main (void)
int i,n=5;
double p = 0.6;
float sum=0;
printf("-------------------------------------------------------\n");
sum=sum+k;
printf("%d\t\t%f\t\t%f\n",i,k,sum);
printf("\n");
return 0;
18
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./binomial.out
19
M.Sc.I.T. Semester I Data Analysis Tools
#include <gsl/gsl_randist.h>
int
main (void)
int i, n = 10;
double mu = 3.0;
float sum=0;
printf("-------------------------------------------------------\n");
sum=sum+k;
printf("%d\t\t%f\t\t%f\n",i,k,sum);
printf("\n");
return 0;
20
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./pio.out
21
M.Sc.I.T. Semester I Data Analysis Tools
4. Uniform distribution(uniform.c)
#include <stdio.h>
#include <gsl/gsl_randist.h>
int
main (void)
double x;
int a,b ;
scanf("%lf",&x);
scanf("%d",&a);
scanf("%d",&b);
float sum=0;
printf("-------------------------------------------------------\n");
printf("%lf\t\t%f\n",x,k);
return 0;
22
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./uniform.out
23
M.Sc.I.T. Semester I Data Analysis Tools
#include <stdio.h>
#include <gsl/gsl_randist.h>
int k=3;
/* prints probability */
printf("-------------------------------------------------------\n");
printf("%3.9f\n",pmf);
return 0;
24
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./multinomial.out
25
M.Sc.I.T. Semester I Data Analysis Tools
#include <stdio.h>
#include <gsl/gsl_randist.h>
int x,s,f,n;
n=6;
x=2;//random variable
s=13;//success
f=39;//failure
/* prints probability */
printf("-----------------------------------\n");
printf("%d %3.6f\n",x,pmf);
return 0;
26
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./hyper.out
27
M.Sc.I.T. Semester I Data Analysis Tools
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_cdf.h>
void normal();
void beta();
void gamma1();
void exponential();
void lognormal();
int main()
int choice;
printf("continous distributions\n");
printf("-----------------------\n");
printf("1:Normal distribution\n");
printf("2:Gamma distribution\n");
printf("3:Exponential distribution\n");
printf("4:Beta distribution\n");
printf("5:Lognormal distribution\n");
scanf("%d",&choice);
switch(choice)
28
M.Sc.I.T. Semester I Data Analysis Tools
case 1:
normal();
break;
case 2:
gamma1();
break;
case 3:
exponential();
break;
case 4:
beta();
break;
case 5:
lognormal();
break;
default:
printf("wrong choice\n");
return 0;
void normal()
double P, Q;
double x = 10;
double sigma=5;
double pdf;
29
M.Sc.I.T. Semester I Data Analysis Tools
P = gsl_cdf_gaussian_P (x,sigma);
Q = gsl_cdf_gaussian_Q (x,sigma);
x = gsl_cdf_gaussian_Pinv (P,sigma);
x = gsl_cdf_gaussian_Qinv (Q,sigma);
void gamma1()
double P, Q;
double x = 1.5;
double a=1;
double b=2;
double pdf;
P = gsl_cdf_gamma_P (x,a,b);
Q = gsl_cdf_gamma_Q (x,a,b);
30
M.Sc.I.T. Semester I Data Analysis Tools
x = gsl_cdf_gamma_Pinv (P,a,b);
x = gsl_cdf_gamma_Qinv (Q,a,b);
void exponential()
double P, Q;
double x = 0.05;
double lambda=2;
double pdf;
P = gsl_cdf_exponential_P (x,lambda);
Q = gsl_cdf_exponential_Q (x,lambda);
x = gsl_cdf_exponential_Pinv (P,lambda);
x = gsl_cdf_exponential_Qinv (Q,lambda);
void beta()
31
M.Sc.I.T. Semester I Data Analysis Tools
{
double P, Q;
double x = 0.8;
double a=0.5;
double b=0.5;
double pdf;
P = gsl_cdf_beta_P (x,a,b);
Q = gsl_cdf_beta_Q (x,a,b);
x = gsl_cdf_beta_Pinv (P,a,b);
x = gsl_cdf_beta_Qinv (Q,a,b);
void lognormal()
double P, Q;
double x = 4;
double zeta=2;
double sigma=1.5;
double pdf;
32
M.Sc.I.T. Semester I Data Analysis Tools
P = gsl_cdf_lognormal_P (x,zeta,sigma);
Q = gsl_cdf_lognormal_Q (x,zeta,sigma);
printf ("prob(x > %f) = %f\n", x, Q);
x = gsl_cdf_lognormal_Pinv (P,zeta,sigma);
x = gsl_cdf_lognormal_Qinv (Q,zeta,sigma);
33
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./contdist.out
34
M.Sc.I.T. Semester I Data Analysis Tools
35
M.Sc.I.T. Semester I Data Analysis Tools
36
M.Sc.I.T. Semester I Data Analysis Tools
#include <gsl/gsl_fit.h>
int
main (void)
int i, n = 4;
printf ("\n");
gsl_fit_linear_est (xf,
c0, c1,
37
M.Sc.I.T. Semester I Data Analysis Tools
&yf, &yf_err);
return 0;
38
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type
To execute type:
./regression.out
39
M.Sc.I.T. Semester I Data Analysis Tools
#include <stdio.h>
#include <gsl/gsl_rng.h>
int
main (void)
const gsl_rng_type * T;
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc (T);
gsl_rng_free (r);
return 0;
40
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type :
To execute type:
./globalgen.out
41
M.Sc.I.T. Semester I Data Analysis Tools
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
int i,n;
float x,alpha;
n=atoi(argv[1]);
alpha=atof(argv[2]);
x=0;
for (i=0;i<n;i++)
x=alpha*x + gsl_ran_exponential(r,1);
return(0);
42
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./ranexpo.out 10 0.4
43
M.Sc.I.T. Semester I Data Analysis Tools
#include <stdio.h>
#include <gsl/gsl_rng.h>
int
main (void)
const gsl_rng_type * T;
gsl_rng * r;
int i, n = 10;
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc (T);
gsl_rng_free (r);
return 0;
44
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./ranuniform.out
45
M.Sc.I.T. Semester I Data Analysis Tools
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
int
main (void)
const gsl_rng_type * T;
gsl_rng * r;
int i, n = 10;
T = gsl_rng_default;
r = gsl_rng_alloc (T);
float p=0.3;
/*print n random variates chosen from the binomial distribution with mean
parameter mu */
printf ("\n");
gsl_rng_free (r);
return 0;
}
46
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./ranbinomial.out
47
M.Sc.I.T. Semester I Data Analysis Tools
#include <apop.h>
int main(){
apop_db_open("data-census.db");
gsl_vector *n = apop_query_to_vector("select in_per_capita from income where
state= (select state from geography where name ='North Dakota')");
gsl_vector *s = apop_query_to_vector("select in_per_capita from income where
state= (select state from geography where name ='South Dakota')");
apop_data *t = apop_t_test(n,s);
apop_data_show(t); //show the whole output set...
printf ("\n confidence: %g\n", apop_data_get(t, .rowname="confidence, 2 tail"));
//...or just one value.
}
48
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./paramt.out
49
M.Sc.I.T. Semester I Data Analysis Tools
#include <apop.h>
int main(){
apop_db_open("data-metro.db");
50
M.Sc.I.T. Semester I Data Analysis Tools
OUTPUT:
To compile type:
To execute type:
./nonp.out
51