Some usable scripts, nothing fancy nor really relevant.
 
 
 
 
 
 
Go to file
Philippe Pittoli 678538aa42 Edited on browser 2011-02-15 07:06:13 -08:00
README Edited on browser 2011-02-15 07:06:13 -08:00
apres.c Ajout du script 'apres.c' qui permet de lancer une commande en différé, résultat dans nohup.out 2011-02-07 21:50:49 +01:00
chrono.pl files added 2011-02-03 13:47:29 +01:00
daemon.pl files added 2011-02-03 13:47:29 +01:00
eko.c Some changements 2011-02-07 23:41:38 +01:00
eko2.c Some changements 2011-02-07 23:41:38 +01:00
enMajuscule.pl files added 2011-02-03 13:47:29 +01:00
exoPointeurs.c Some changements 2011-02-07 23:41:38 +01:00
function.c Some changements 2011-02-07 23:41:38 +01:00
getpwent.pl files added 2011-02-03 13:47:29 +01:00
getpwent2.pl files added 2011-02-03 13:47:29 +01:00
humanornot.pl files added 2011-02-03 13:47:29 +01:00
humanornot2.pl files added 2011-02-03 13:47:29 +01:00
lePlusGros.pl files added 2011-02-03 13:47:29 +01:00
matrice1.c Some changements 2011-02-07 23:41:38 +01:00
matrice2.c Some changements 2011-02-07 23:41:38 +01:00
max.pl files added 2011-02-03 13:47:29 +01:00
maxcourt.pl files added 2011-02-03 13:47:29 +01:00
mini_shell.c You can add 2 args on the command line 2011-02-13 11:26:34 +01:00
minmax.c Some changements 2011-02-07 23:41:38 +01:00
monswap.c Some changements 2011-02-07 23:41:38 +01:00
morceau_miroir.c Some changements 2011-02-07 23:41:38 +01:00
multi_chrono.pl files added 2011-02-03 13:47:29 +01:00
nbmots.pl files added 2011-02-03 13:47:29 +01:00
silent_cmp.pl files added 2011-02-03 13:47:29 +01:00
squeeze.c Some changements 2011-02-07 23:41:38 +01:00
strdup2.c Some changements 2011-02-07 23:41:38 +01:00
supprime.c Ajout du script 'apres.c' qui permet de lancer une commande en différé, résultat dans nohup.out 2011-02-07 21:50:49 +01:00
swapp.c Some changements 2011-02-07 23:41:38 +01:00
testargs.c Some changements 2011-02-07 23:41:38 +01:00
tout.c Some changements 2011-02-07 23:41:38 +01:00
tube.pl files added 2011-02-03 13:47:29 +01:00
wc.pl i've made some additions to the file to explain the source code 2011-02-03 14:18:19 +01:00
wordcount.c Some changements 2011-02-07 23:41:38 +01:00

README

Hello everyone

You can watch all my little scripts in C and Perl.

Enjoy !

MANGEZ

SELECT date, SUM(dollars) AS total_dollars,
	SUM(SUM(dollars)) OVER(ORDER BY date ROWS UNBOUNDED PRECEDING) AS run_dollars,
	SUM(quantity) AS total_qty,
	SUM(SUM(quantity)) OVER(ORDER BY date ROWS UNBOUNDED PRECEDING) AS run_qty
	FROM aroma.period a, aroma.sales b, aroma.product c
	WHERE a.perkey = b.perkey
	AND c.prodkey = b.prodkey
	AND c.classkey = b.classkey
	AND year = 2006
	AND month = 'JAN'
	AND prod_name = 'Aroma Roma'
GROUP BY date
ORDER BY date;


SUM(SUM(dollars)) OVER(ORDER BY date ROWS UNBOUNDED PRECEDING) 

OVER = OLAP aggregation function

MOVING Average = moyenne sur quelques jours pour faire une courbe de la moyenne (moins en dents de scie)


SELECT date, SUM(dollars) AS total_dollars,
	SUM(SUM(dollars)) OVER(PARTITION BY week ORDER BY date
	ROWS UNBOUNDED PRECEDING) AS run_dollars,
	SUM(quantity) AS total_qty,
	SUM(SUM(quantity)) OVER(PARTITION BY week ORDER BY date
	ROWS UNBOUNDED PRECEDING) AS run_qty
	FROM aroma.period a, aroma.sales b, aroma.product c
	WHERE a.perkey = b.perkey
	AND c.prodkey = b.prodkey
	AND c.classkey = b.classkey
	AND year = 2006
	AND month = 'JAN'
	AND prod_name = 'Aroma Roma'
GROUP BY week, date
ORDER BY week, date;

PARTITION BY week = Faire la somme mais par semaine


SELECT date, SUM(dollars) AS total_dollars,
	SUM(SUM(dollars)) OVER (PARTITION BY week ORDER BY date
	ROWS UNBOUNDED PRECEDING) AS run_dollars,
	SUM(quantity) AS total_qty,
	SUM(SUM(quantity)) OVER(PARTITION BY week ORDER BY date
	ROWS UNBOUNDED PRECEDING) AS run_qty, week
	FROM aroma.period a, aroma.sales b, aroma.product c
	WHERE a.perkey = b.perkey
	AND c.prodkey = b.prodkey
	AND c.classkey = b.classkey
	AND year = 2006
	AND month = 'JAN'
	AND prod_name = 'Aroma Roma'
GROUP BY week, date
ORDER BY week, date;


SELECT prod_name, SUM(dollars) AS total_sales, SUM(quantity) AS total_qty,
	DEC(sum(dollars)/sum(quantity), 7, 2) AS price
	FROM aroma.product a, aroma.sales b, aroma.period c
	WHERE a.prodkey = b.prodkey
	AND a.classkey = b.classkey
	AND c.perkey = b.perkey
	AND year = 2004
GROUP BY prod_name
ORDER BY price;

dec(sum(dollars)/sum(quantity), 7, 2) AS price


SELECT t1.date, sales_cume_west, sales_cume_south,
	sales_cume_west - sales_cume_south AS west_vs_south
	FROM
	(SELECT date, SUM(dollars) AS total_sales,
	SUM(SUM(dollars)) OVER(ORDER BY date
	ROWS UNBOUNDED PRECEDING) AS sales_cume_west
	FROM aroma.market a,
	aroma.store b,
	aroma.sales c,
	aroma.period d
	WHERE a.mktkey = b.mktkey
	AND b.storekey = c.storekey
	AND d.perkey = c.perkey
	AND year = 2006
	AND month = 'MAR'
	AND region = 'West'
	GROUP BY date) AS t1
	JOIN 
	(SELECT date, SUM(dollars) AS total_sales,
	SUM(SUM(dollars)) OVER(ORDER BY date ROWS UNBOUNDED PRECEDING) AS sales_cume_south
	FROM aroma.market a,
	aroma.store b,
	aroma.sales c,
	aroma.period d
	WHERE a.mktkey = b.mktkey
	AND b.storekey = c.storekey
	AND d.perkey = c.perkey
	AND year = 2006
	AND month = 'MAR'
	AND region = 'South'
	GROUP BY date) AS t2
ON t1.date = t2.date
ORDER BY date;




SELECT city, week, SUM(dollars) AS sales,
	DEC(AVG(SUM(dollars)) OVER(partition by city
	ORDER BY city, week ROWS 2 PRECEDING),7,2) AS mov_avg,
	SUM(SUM(dollars)) OVER(PARTITION BY city
	ORDER BY week ROWS unbounded PRECEDING) AS run_sales
	FROM aroma.store a,
	aroma.sales b,
	aroma.period c
	WHERE a.storekey = b.storekey
	AND c.perkey = b.perkey
	AND qtr = 'Q3_05'
	AND city IN ('San Jose', 'Miami')
GROUP BY city, week;


ROWS n PRECEDING (ou on peut aussi dire : FOLLOWING )



SELECT date, SUM(quantity) AS day_qty,
	DEC(SUM(SUM(quantity)) OVER(ORDER BY date
	ROWS 6 PRECEDING),7,2) AS mov_sum
	FROM aroma.sales a, aroma.period b, aroma.product c
	WHERE b.perkey = a.perkey
	AND c.classkey = a.classkey
	AND c.prodkey = a.prodkey
	AND year = 2006
	AND month = 'MAR'
	AND prod_name = 'Demitasse Ms'
GROUP BY date
ORDER BY date;

REPONSES :

# Total du montant des ventes par catégorie

select c.class_type, sum(s.dollars) as total
from aroma.class c, aroma.sales s, aroma.product p
where c.classkey = p.classkey
and p.prodkey = s.prodkey
and p.classkey = s.classkey
group by c.class_type
order by total desc

# Pourcentage du montant des ventes de chaque catégorie

select c.class_type, dec(100*sum(s.dollars)/(select sum(dollars) from aroma.sales),7,0) as part
from aroma.class c, aroma.sales s, aroma.product p
where c.classkey = p.classkey
and p.prodkey = s.prodkey
and p.classkey = s.classkey
group by c.class_type
order by part desc

# Classement des ventes par classes de produit

select c.class_type, dec(100*sum(s.dollars)/(select sum(dollars) from aroma.sales),7,0) as part, rank() over(order by sum(s.dollars) desc) as rang
from aroma.class c, aroma.sales s, aroma.product p
where c.classkey = p.classkey
and p.prodkey = s.prodkey
and p.classkey = s.classkey
group by c.class_type
order by part desc

# Produit le plus vendu, pourcentage correspondant

select p.prodkey, p.classkey, p.prod_name, p.pkg_type, dec(100*sum(s.dollars)/(select sum(dollars) from aroma.sales),7,0) as part
from aroma.sales s, aroma.product p
where p.prodkey = s.prodkey
and p.classkey = s.classkey
group by p.prodkey, p.classkey, p.prod_name, p.pkg_type
order by part desc

# Montant des ventes des produits par semaine

select p.prodkey, p.classkey, p.prod_name, p.pkg_type, t.week, sum(s.dollars) as montant
from aroma.sales s, aroma.product p, aroma.period t
where p.prodkey = s.prodkey
and p.classkey = s.classkey
and s.perkey = t.perkey
group by p.prodkey, p.classkey, p.prod_name, p.pkg_type,t.week
order by t.week

# Classement des produits par montant des ventes décroissant pour chaque semaine

select p.prodkey, p.classkey, p.prod_name, p.pkg_type, t.week, sum(s.dollars) as montant, rank() over(partition by week order by week, sum(s.dollars) desc) as rang
from aroma.sales s, aroma.product p, aroma.period t
where p.prodkey = s.prodkey
and p.classkey = s.classkey
and s.perkey = t.perkey
group by p.prodkey, p.classkey, p.prod_name, p.pkg_type,t.week
order by t.week, rang

# Classement moyen des produits en vente hebdomadaire

select t.prodkey, t.classkey, t.prod_name, t.pkg_type, avg(rang) as rang_moyen
from (select p.prodkey, p.classkey, p.prod_name, p.pkg_type, t.week, sum(s.dollars) as montant, rank() over(partition by week order by week, sum(s.dollars) desc) as rang
from aroma.sales s, aroma.product p, aroma.period t
where p.prodkey = s.prodkey
and p.classkey = s.classkey
and s.perkey = t.perkey
group by p.prodkey, p.classkey, p.prod_name, p.pkg_type,t.week
order by t.week, rang) as t(prodkey,classkey,prod_name,pkg_type,week,montant,rang)
group by t.prodkey,t.classkey, t.prod_name, t.pkg_type

# Montant moyen des ventes par jour de la semaine

select ti.day, avg(ti.montant) as moyenne
from (select t.day,sum(dollars)
  from aroma.sales s, aroma.period t
  where s.perkey = t.perkey
  group by t.perkey,t.day) as ti(day,montant)
group by ti.day
order by moyenne desc