Guruh talabasi Abdig’opporov javoxir Mysql 1-2-amaliy ishlar



Download 353,77 Kb.
bet43/43
Sana18.07.2022
Hajmi353,77 Kb.
#818857
1   ...   35   36   37   38   39   40   41   42   43
Bog'liq
311-18 AJ

Advanced Exercises

  1. Adding Photo: We could store photo in MySQL using data type of BLOB (Binary Large Object) (up to 64KB), MEDIUMBLOB (up to 16MBytes), LONGBOLB (up to 4GBytes). For example,

  2. -- Use function LOAD_FILE to load a picture file into a BLOB field

  3. UPDATE vehicles SET photo=LOAD_FILE('d:/temp/car.jpg') WHERE veh_reg_no = 'SBA1111A';

SELECT * FROM vehicles WHERE veh_reg_no = 'SBA1111A' \G
You can conveniently load and view the photo via graphical tools such as MySQL Workbench. To load a image in MySQL Workbench ⇒ right-click on the cell ⇒ Load Value From File ⇒ Select the image file. To view the image ⇒ right-click on the BLOB cell ⇒ Open Value in Editor ⇒ choose "Image" pane.
I also include a Java program for reading and writing image BLOB from/to the database, based on this example: "TestImageBLOB.java".

  1. VIEW: Create a VIEW called rental_prices on the rental_records with an additional column called price. Show all the records of the VIEW.

  2. DROP VIEW IF EXISTS rental_prices;

  3. CREATE VIEW rental_prices

  4. AS

  5. SELECT

  6. v.veh_reg_no AS `Vehicle No`,

  7. v.daily_rate AS `Daily Rate`,

  8. c.name AS `Customer Name`,

  9. c.discount*100 AS `Customer Discount (%)`,

  10. r.start_date AS `Start Date`,

  11. r.end_date AS `End Date`,

  12. DATEDIFF(r.end_date, r.start_date) AS `Duration`,

  13. -- Compute the rental price

  14. -- Preferred customer has discount, 20% discount for 7 or more days

  15. -- CAST the result from DOUBLE to DECIMAL(8,2)

  16. CAST(

  17. IF (DATEDIFF(r.end_date, r.start_date) < 7,

  18. DATEDIFF(r.end_date, r.start_date)*daily_rate*(1-discount),

  19. DATEDIFF(r.end_date, r.start_date)*daily_rate*(1-discount)*0.8)

  20. AS DECIMAL(8,2)) AS price

  21. FROM rental_records AS r

  22. INNER JOIN vehicles AS v USING (veh_reg_no)

  23. INNER JOIN customers AS c USING (customer_id);


  24. DESC `rental_prices`;

  25. SHOW CREATE VIEW `rental_prices` \G


  26. -- Try selecting all rows

SELECT * FROM `rental_prices`;
It is probably easier to compute the price using a program/procedure, instead of inside the view.

  1. From the payments table, create a view to show the outstanding balance.

  2. Define more views.

  3. FUNCTION: Write a function to compute the rental price.

  4. Define more procedures and functions.

  5. TRIGGER: Write a trigger for the created_date and created_by columns of the payments table.

  6. Define more triggers.

  7. Implement discount on weekday (Monday to Friday, except public holiday): Need to set up a new table called public_hoilday with columns date and description. Use function DAYOFWEEK (1=Sunday, …, 7=Saturday) to check for weekday or weekend.

  8. -- pseudocode for calculating rental price

  9. price = 0;

  10. for each date from start_date to end_date {

  11. if date is weekend or public_holiday, price += daily_rate;

  12. else price += daily_rate*(1-discount);

  13. }

  14. if (duration >= 7) price *= (1 - long_duration_discount);

price *= (1 - perferred_customer_discount);
7.2 Product Sales Database

Download 353,77 Kb.

Do'stlaringiz bilan baham:
1   ...   35   36   37   38   39   40   41   42   43




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish