Beruflich Dokumente
Kultur Dokumente
OLAP
OLAP
miden algn valor y pueden agregarse (cantidad vendida) definen las dimensiones en las que se ven los atributos de medida y los resmenes de los atributos de medida (nombre, color, talla) datos que pueden modelarse como atributos de dimensin y de medida, frecuentemente mediante una tabla de tabulacin cruzada
Atributos de dimensin
Datos multidimensionales
OLAP
oscuro Falda Vestido Camisa Pantaln Total 8 20 14 20 62 pastel 35 10 7 2 54 blanco 10 5 28 5 48 Total 53 35 49 27 164
OLAP
Las tablas de tabulacin cruzada bidimensionales se pueden apilar con una tercer variable (tiempo frecuentemente) para formar un cubo de decisin
oscuro pastel blanco Total oscuro pastel blanco Total oscuro pastel blanco Total Falda 8 35 10 53 Falda 8 35 10 53 Falda 8 35 10 53 Vestido 20 10 5 35 Vestido 20 10 5 35 Vestido 20 10 5 35 Camisa 14 7 28 49 Camisa 14 7 28 49 Camisa 14 7 28 49 Pantal 20 2 5 27 Pantal 20 2 5 27 n Pantal 20 2 5 27 n Total 62 54 48 164 n Total 62 54 48 164 Total 62 54 48 164
OLAP
Modificador de agrupacin
WITH
ROLLUP
OLAP
mysql> SELECT year, SUM(profit) FROM sales GROUP BY year; +------+-------------+ | year | SUM(profit) | +------+-------------+ | 2000 | 4525 | | 2001 | 3010 | +------+-------------+
OLAP
mysql> SELECT year, SUM(profit) FROM sales GROUP BY year WITH ROLLUP; +------+-------------+ | year | SUM(profit) | +------+-------------+ | 2000 | 4525 | | 2001 | 3010 | | NULL | 7535 | +------+-------------+
OLAP
mysql> SELECT year, country, product, SUM(profit) -> FROM sales -> GROUP BY year, country, product; +------+---------+------------+-------------+ | year | country | product | SUM(profit) | +------+---------+------------+-------------+ | 2000 | Finland | Computer | 1500 | | 2000 | Finland | Phone | | 2000 | India | Calculator | | 2000 | India | Computer | | 2000 | USA | Calculator | | | | 2000 | USA | Computer | 2001 | Finland | Phone | 2001 | USA | 2001 | USA | 2001 | USA 100 | 150 | 1200 | 75 | 1500 | 10 | 50 | 2700 | 250 |
| Calculator | | Computer | | TV |
+------+---------+------------+-------------+
OLAP
mysql> SELECT year, country, product, SUM(profit) -> FROM sales -> GROUP BY year, country, product WITH ROLLUP; +------+---------+------------+-------------+ | year | country | product | SUM(profit) |
+------+---------+------------+-------------+ | 2000 | Finland | Computer | 2000 | Finland | Phone | 2000 | Finland | NULL | 2000 | India | 2000 | India | 2000 | India | 2000 | USA | 2000 | USA | 2000 | USA | 2000 | NULL | | | 1500 | 100 | 1600 | 150 | 1200 | 1350 | 75 | 1500 | 1575 | 4525 | 10 | 10 | 50 | 2700 | 250 | 3000 | 3010 | 7535 |
| 2001 | Finland | Phone | 2001 | Finland | NULL | 2001 | USA | 2001 | USA | 2001 | USA | 2001 | USA | 2001 | NULL | NULL | NULL
+------+---------+------------+-------------+
Cursores
Cursores
Estructura de control utilizada para el recorrido (y potencial procesamiento) de los registros del resultado de una consulta Se utilizan para el procesamiento individual de las filas devueltas por una consulta
Cursores
CREATE PROCEDURE
miProcedimiento()
BEGIN DECLARE productId INT; DECLARE productName VARCHAR(255); DECLARE done BOOLEAN DEFAULT FALSE; DECLARE c1 CURSOR FOR select productId, productName from products; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE; OPEN c1; REPEAT FETCH c1 INTO productId, productName; IF NOT done THEN END IF; UNTIL done END REPEAT; CLOSE c1; END//