mysql> CREATE TABLE Products (
Id INT AUTO_INCREMENT PRIMARY KEY, ProductName VARCHAR(30) NOT NULL, Manufacturer VARCHAR(20) NOT NULL, ProductCount INT DEFAULT 0,
Price DECIMAL NOT NULL
);
Query OK, 0 rows affected (0.46 sec)
mysql>
mysql> INSERT INTO Products(ProductName, Manufacturer, ProductCount, Price) VALUES
('iPhone X', 'Apple', 3, 76000),
('iPhone 8', 'Apple', 2, 51000),
('iPhone 7', 'Apple', 5, 32000),
('Galaxy S9', 'Samsung', 2, 56000),
('Galaxy S8', 'Samsung', 1, 46000),
('Honor 10', 'Huawei', 5, 28000),
('Nokia 8', 'HMD Global', 6, 38000);
Query OK, 7 rows affected (0.17 sec) Records: 7 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM PRODUCTS;
+ + + + + +
| Id | ProductName | Manufacturer | ProductCount | Price |
+ + + + + +
| 1 | iPhone X | Apple | 3 | 76000 |
| 2 | iPhone 8 | Apple | 2 | 51000 |
| 3 | iPhone 7 | Apple | 5 | 32000 |
| 4 | Galaxy S9 | Samsung | 2 | 56000 |
| 5 | Galaxy S8 | Samsung | 1 | 46000 |
| 6 | Honor 10 | Huawei | 5 | 28000 |
| 7 | Nokia 8 | HMD Global | 6 | 38000 |
+ + + + + +
7 rows in set (0.00 sec)
mysql> SELECT AVG(Price) AS Average_Price FROM Products;
+ +
| Average_Price |
+ +
| 46714.2857 |
+ +
1 row in set (0.10 sec)
mysql> SELECT AVG(Price) FROM Products WHERE Manufacturer='Apple';
+ +
| AVG(Price) |
+ +
| 53000.0000 |
+ +
1 row in set (0.00 sec)
mysql> SELECT AVG(Price * ProductCount) FROM Products
;
+ +
| AVG(Price * ProductCount) |
+ +
| 145142.8571 |
+ +
1 row in set (0.00 sec)
mysql> SELECT AVG(Price * ProductCount) AS JAMI FROM Products
;
+ +
| JAMI |
+ +
| 145142.8571 |
+ +
1 row in set (0.00 sec)
mysql>
mysql> SELECT COUNT(*) FROM Products;
+ +
| COUNT(*) |
+ +
| 7 |
+ +
1 row in set (0.13 sec)
mysql>
mysql> SELECT COUNT(Manufacturer) FROM Products;
+ +
| COUNT(Manufacturer) |
+ +
| 7 |
+ +
1 row in set (0.00 sec)
mysql> SELECT MIN(Price), MAX(Price) FROM Products;
+ + +
| MIN(Price) | MAX(Price) |
+ + +
| 28000 | 76000 |
+ + +
1 row in set (0.05 sec)
mysql> SELECT SUM(ProductCount) FROM Products;
+ +
| SUM(ProductCount) |
+ +
| 24 |
+ +
1 row in set (0.00 sec)
mysql> SELECT SUM(ProductCount * Price) FROM Products
;
+ +
| SUM(ProductCount * Price) |
+ +
| 1016000 |
+ +
1 row in set (0.00 sec)
mysql> SELECT COUNT(DISTINCT Manufacturer) FROM Products;
+ +
| COUNT(DISTINCT Manufacturer) |
+ +
| 4 |
+ +
1 row in set (0.05 sec)
mysql> SELECT COUNT(ALL Manufacturer) FROM Products;
+ +
| COUNT(ALL Manufacturer) |
+ +
| 7 |
+ +
1 row in set (0.00 sec)
mysql> SELECT COUNT(*) AS ProdCount, SUM(ProductCount) AS TotalCount, MIN(Price) AS MinPrice, MAX(Price) AS MaxPrice, AVG(Price) AS AvgPrice
FROM Products;
+ + + + + +
| ProdCount | TotalCount | MinPrice | MaxPrice | AvgPrice |
+ + + + + +
| 7 | 24 | 28000 | 76000 | 46714.2857 |
+ + + + + +
1 row in set (0.00 sec)
mysql> SELECT GROUP_CONCAT(Price) FROM Products;
+ +
| GROUP_CONCAT(Price) |
+ +
| 76000,51000,32000,56000,46000,28000,38000 |
+ +
1 row in set (0.00 sec)
mysql> SELECT GROUP_CONCAT(PRODUCTNAME) FROM Products;
+ +
| GROUP_CONCAT(PRODUCTNAME) |
+ +
| iPhone X,iPhone 8,iPhone 7,Galaxy S9,Galaxy S8,Honor 10,Nokia 8 |
+ +
1 row in set (0.00 sec)
Foydalanilgan veb-saytlar.
https://muhaz.org/download/4--amaliy-mashgulot-mavzu-malumotlarni-tanlash-va-ular-ustida.doc
http://www.hozir.org/2-amaliy-ish-mavzu-malumotlarni-tanlash-va-ular-ustida-amallar-v2.html
http://azkurs.org/malumotlar-bazasi-mustaqil-ish.html?page=3
https://e-ibrary.namdu.uz/30%20%D0%A2%D0%B5%D1%85%D0%BD%D0%B8%D0%BA%D0%B0%20%D1%84%D0%B0%D0%BD%D0%BB%D0%B0%D1%80/informatika_9_uzb.pdf
https://ilmiy.bmti.uz/blib/files/80/B.%20Ergashev%20-%20Ma%60lumotlar%20bazasini%20boshqarish%20tizimlari.PDF
Dostları ilə paylaş: |