0% found this document useful (0 votes)
13 views3 pages

Dwmexp 1

datawarehousing and management

Uploaded by

damafa7880
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Dwmexp 1

datawarehousing and management

Uploaded by

damafa7880
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

mysql> create database vikas_dwm ;

Query OK, 1 row affected (0.04 sec)

mysql> use vikas_dwm ;


Database changed

mysql> CREATE TABLE Product (


-> id INT PRIMARY KEY,
-> type VARCHAR(50),
-> category VARCHAR(50),
-> cost DECIMAL(10, 2),
-> quantity INT
-> );
Query OK, 0 rows affected (0.09 sec)

mysql> INSERT INTO Product (id, type, category, cost, quantity) VALUES
-> (1, 'Laptop', 'Electronics', 1000.00, 50),
-> (2, 'Smartphone', 'Electronics', 600.00, 200),
-> (3, 'Tablet', 'Electronics', 300.00, 100),
-> (4, 'Monitor', 'Accessories', 150.00, 75);
Query OK, 4 rows affected (0.03 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from product ;


+ + + + + +
| id | type | category | cost | quantity |
+ + + + + +
| 1 | Earphone | Electronics | 1000.00 | 50 |
| 2 | Headphone | Electronics | 600.00 | 200 |
| 3 | Speaker | Electronics | 300.00 | 100 |
| 4 | wired | Accessories | 150.00 | 75 |
+ + + + + +
4 rows in set (0.00 sec)

mysql> CREATE TABLE Supplier (


-> id INT PRIMARY KEY,
-> name VARCHAR(100),
-> contact VARCHAR(50),
-> location VARCHAR(100)
-> );
Query OK, 0 rows affected (0.03 sec)

mysql> INSERT INTO Supplier (id, name, contact, location) VALUES


-> (1, 'ElectroWorld', '123-456-7890', 'Mumbai'),
-> (2, 'TechSupply Co.', '987-654-3210', 'Delhi'),
-> (3, 'Gadget Hub', '456-789-0123', 'Bangalore'),
-> (4, 'Device Central', '321-654-9870', 'Chennai');
Query OK, 4 rows affected (0.01 sec)

mysql> select * from Supplier ;


+ + + + +
| id | name | contact | location |
+ + + + +
| 1 | ElectroWorld | 123-456-7890 | Mumbai |
| 2 | TechSupply Co. | 987-654-3210 | Delhi |
| 3 | Gadget Hub | 456-789-0123 | Bangalore |
| 4 | Device Central | 321-654-9870 | Chennai |
+ + + + +
4 rows in set (0.00 sec)
mysql> CREATE TABLE Location (
-> pincode INT PRIMARY KEY,
-> region VARCHAR(50),
-> city VARCHAR(50),
-> state VARCHAR(50)
-> );
Query OK, 0 rows affected (0.03 sec)

mysql>
mysql> INSERT INTO Location (pincode, region, city, state) VALUES
-> (400001, 'Western Region', 'Mumbai', 'Maharashtra'),
-> (110001, 'Northern Region', 'Delhi', 'Delhi'),
-> (560001, 'Southern Region', 'Bangalore', 'Karnataka'),
-> (600001, 'Southern Region', 'Chennai', 'Tamil Nadu');
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from Location ;


+ + + + +
| pincode | region | city | state |
+ + + + +
| 110001 | Northern Region | Delhi | Delhi |
| 400001 | Western Region | Mumbai | Maharashtra |
| 560001 | Southern Region | Bangalore | Karnataka |
| 600001 | Southern Region | Chennai | Tamil Nadu |
+ + + + +
4 rows in set (0.00 sec)

mysql> CREATE TABLE Time (


-> id INT PRIMARY KEY,
-> year INT,
-> month VARCHAR(20),
-> day INT
-> );
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO Time (id, year, month, day) VALUES


-> (1, 2023, 'January', 15),
-> (2, 2023, 'February', 10),
-> (3, 2023, 'March', 5),
-> (4, 2023, 'April', 20);
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from time ;


+ + + + +
| id | year | month | day |
+ + + + +
| 1 | 2023 | January | 15 |
| 2 | 2023 | February | 10 |
| 3 | 2023 | March | 5 |
| 4 | 2023 | April | 20 |
+ + + + +
4 rows in set (0.00 sec)

mysql> CREATE TABLE Fact (


-> product_id INT,
-> supplier_id INT,
-> time_id INT,
-> location_pincode INT,
-> revenue DECIMAL(15, 2),
-> inventory_of_sales INT,
-> profit DECIMAL(15, 2),
-> PRIMARY KEY (product_id, supplier_id, time_id,
location_pincode),
-> FOREIGN KEY (product_id) REFERENCES Product(id),
-> FOREIGN KEY (supplier_id) REFERENCES Supplier(id),
-> FOREIGN KEY (time_id) REFERENCES Time(id),
-> FOREIGN KEY (location_pincode) REFERENCES Location(pincode)
-> );
Query OK, 0 rows affected (0.09 sec)

mysql> INSERT INTO Fact (product_id, supplier_id, time_id,


location_pincode, revenue, inventory_of_sales, profit) VALUES
-> (1, 1, 1, 400001, 50000.00, 10, 15000.00),
-> (2, 2, 2, 110001, 120000.00, 50, 30000.00),
-> (3, 3, 3, 560001, 30000.00, 20, 9000.00),
-> (4, 4, 4, 600001, 11250.00, 5, 3750.00);
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from Fact ;


+ + + + + + + +
| prod_id | supp_id | time | pincode | revenue | inventory | profit |
| | | _id | | generated | of_sales | earned |
+ + + + + + |
| 1 | 1 | 1 | 400001 | 50000.00 | 10| 15000.00 |
| 2 | 2 | 2 | 110001 | 120000.00 | 50| 30000.00 |
| 3 | 3 | 3 | 560001 | 30000.00 | 20| 9000.00 |
| 4 | 4 | 4 | 600001 | 11250.00 | 5| 3750.00 |
+ + + + + + + +
rows in set (0.00 sec)

To find Revenue Generated in month of february

mysql> SELECT SUM(f.revenue) AS total_revenue


-> FROM Fact f
-> JOIN Time t ON f.time_id = t.id
-> WHERE t.month = 'February';
+ +
| total_revenue |
+ +
| 120000.00 |
+ +
1 row in set (0.01 sec)

You might also like