give code sql
تم الإنشاء في: ١٧ يونيو ٢٠٢٥
تم الإنشاء في: ١٧ يونيو ٢٠٢٥
pythonfrom PIL import Image import matplotlib.pyplot as plt img = Image.open('/mnt/data/87819068_SKC1762025_18333.png') plt.imshow(img) plt.axis('off') (-0.5, 1365.5, 767.5, -0.5)
python# crop bottom area where ER diagram located width, height = img.size # approximate crop coordinates: left 0-?? we want bottom part maybe entire left half bottom crop = img.crop((0, int(height*0.5), int(width*0.5), height)) plt.imshow(crop) plt.axis('off') (-0.5, 682.5, 383.5, -0.5)
python# further zoom in for clarity reading text maybe degrade plt.figure(figsize=(8,4)) plt.imshow(crop) plt.axis('off') (-0.5, 682.5, 383.5, -0.5)
python# crop small area of ER subdiagram in original image by coordinates; use approximate bounding boxes # Let's crop product box region # manually estimate coordinates by display? Hard. # Let's zoom by cropping bounding rectangle around cluster near center. crop2 = img.crop((100, 400, 600, 800)) plt.imshow(crop2) plt.axis('off') (-0.5, 499.5, 399.5, -0.5)
python# zoom 3x on product text area product_crop = crop2.crop((30, 220, 200, 360)) plt.figure(figsize=(4,3)) plt.imshow(product_crop) plt.axis('off') (-0.5, 169.5, 139.5, -0.5)
pythonimport cv2 import numpy as np # use cv2 to enlarge image region # enlarge product box region by approximate; manually observe coordinates: product appears at about x 40 to 270 in crop2 ph = img.height pw = img.width # approximate product region prod = img.crop((180, 450, 430, 650)) prod_big = prod.resize((prod.width*3, prod.height*3), Image.NEAREST) plt.imshow(prod_big) plt.axis('off') (-0.5, 749.5, 599.5, -0.5)
pythonsales = img.crop((450, 450, 700, 650)) sales_big = sales.resize((sales.width*3, sales.height*3), Image.NEAREST) plt.imshow(sales_big) plt.axis('off') (-0.5, 749.5, 599.5, -0.5)
pythondist = img.crop((800, 450, 1040, 650)) dist_big = dist.resize((dist.width*3, dist.height*3), Image.NEAREST) plt.imshow(dist_big) plt.axis('off') (-0.5, 719.5, 599.5, -0.5)
pythonter = img.crop((180, 650, 430, 900)) ter_big = ter.resize((ter.width*3, ter.height*3), Image.NEAREST) plt.imshow(ter_big) plt.axis('off') (-0.5, 749.5, 749.5, -0.5)
pythoncomp = img.crop((450, 650, 700, 900)) comp_big = comp.resize((comp.width*3, comp.height*3), Image.NEAREST) plt.imshow(comp_big) plt.axis('off') (-0.5, 749.5, 749.5, -0.5)
pythonemp = img.crop((800, 650, 1040, 900)) emp_big = emp.resize((emp.width*3, emp.height*3), Image.NEAREST) plt.imshow(emp_big) plt.axis('off') (-0.5, 719.5, 749.5, -0.5)
python# crop more of left panel below crop2 to capture question details crop3 = img.crop((0, 550, 600, 1400)) plt.imshow(crop3) plt.axis('off') (-0.5, 599.5, 849.5, -0.5)
pythonter_big2 = ter.resize((ter.width*4, ter.height*4), Image.NEAREST) plt.figure(figsize=(4,4)) plt.imshow(ter_big2) plt.axis('off') (-0.5, 999.5, 999.5, -0.5)
pythoncomp_big2 = comp.resize((comp.width*4, comp.height*4), Image.NEAREST) plt.imshow(comp_big2) plt.axis('off') (-0.5, 999.5, 999.5, -0.5)
pythonemp_big2 = emp.resize((emp.width*4, emp.height*4), Image.NEAREST) plt.imshow(emp_big2) plt.axis('off') (-0.5, 959.5, 999.5, -0.5)
Here’s a clean MySQL DDL script that recreates every table in the ER diagram exactly as shown, with primary- and foreign-key relationships wired up so you can run it in the “Current Code” pane straight away:
sql/* ---------- start fresh (order matters because of FK deps) ---------- */ DROP TABLE IF EXISTS sales; DROP TABLE IF EXISTS distributor; DROP TABLE IF EXISTS competitors; DROP TABLE IF EXISTS product; DROP TABLE IF EXISTS territories; DROP TABLE IF EXISTS employee; /* ---------- employee ---------- */ CREATE TABLE employee ( employee_id INT PRIMARY KEY, employee_name VARCHAR(45), employee_gender VARCHAR(10), employee_age INT ) ENGINE = InnoDB; /* ---------- product ---------- */ CREATE TABLE product ( sku_id INT PRIMARY KEY, product_name VARCHAR(45), product_brand VARCHAR(45), product_size INT, product_price FLOAT ) ENGINE = InnoDB; /* ---------- territories ---------- */ CREATE TABLE territories ( territories_id INT PRIMARY KEY, territories_state VARCHAR(45), territories_city VARCHAR(45), territories_region VARCHAR(10), territories_star VARCHAR(10), territories_population FLOAT ) ENGINE = InnoDB; /* ---------- distributor ---------- */ CREATE TABLE distributor ( distributor_id INT PRIMARY KEY, distributor_name VARCHAR(45), distributor_city VARCHAR(45), distributor_warehouses_count INT, distributor_last_yr_sales FLOAT, employee_id INT, CONSTRAINT fk_distributor_employee FOREIGN KEY (employee_id) REFERENCES employee(employee_id) ) ENGINE = InnoDB; /* ---------- sales ---------- */ CREATE TABLE sales ( sales_id INT PRIMARY KEY, sales_date TIMESTAMP, quantity INT, discount FLOAT, sku_id INT, territories_id INT, distributor_id INT, CONSTRAINT fk_sales_product FOREIGN KEY (sku_id) REFERENCES product(sku_id), CONSTRAINT fk_sales_territories FOREIGN KEY (territories_id) REFERENCES territories(territories_id), CONSTRAINT fk_sales_distributor FOREIGN KEY (distributor_id) REFERENCES distributor(distributor_id) ) ENGINE = InnoDB; /* ---------- competitors ---------- */ CREATE TABLE competitors ( competitor_name VARCHAR(45), product_name VARCHAR(45), PRIMARY KEY (competitor_name, product_name) ) ENGINE = InnoDB;
How to use it
INSERT
statements or write your analytical queries on top of this schema as required by the next part of the assignment.That’s all you need to get the schema ready—happy querying!
its very long
Got it — here’s a much more compact version (no comments, no extra options) that still builds the six tables and their key relationships. Just copy-paste as-is:
sql/* reset */ DROP TABLE IF EXISTS sales, distributor, competitors, product, territories, employee; /* core tables */ CREATE TABLE employee( employee_id INT PRIMARY KEY, employee_name VARCHAR(45), employee_gender VARCHAR(10), employee_age INT ); CREATE TABLE product( sku_id INT PRIMARY KEY, product_name VARCHAR(45), product_brand VARCHAR(45), product_size INT, product_price FLOAT ); CREATE TABLE territories( territories_id INT PRIMARY KEY, territories_state VARCHAR(45), territories_city VARCHAR(45), territories_region VARCHAR(10), territories_star VARCHAR(10), territories_population FLOAT ); CREATE TABLE distributor( distributor_id INT PRIMARY KEY, distributor_name VARCHAR(45), distributor_city VARCHAR(45), distributor_warehouses_count INT, distributor_last_yr_sales FLOAT, employee_id INT, FOREIGN KEY (employee_id) REFERENCES employee(employee_id) ); CREATE TABLE sales( sales_id INT PRIMARY KEY, sales_date TIMESTAMP, quantity INT, discount FLOAT, sku_id INT, territories_id INT, distributor_id INT, FOREIGN KEY (sku_id) REFERENCES product(sku_id), FOREIGN KEY (territories_id) REFERENCES territories(territories_id), FOREIGN KEY (distributor_id) REFERENCES distributor(distributor_id) ); CREATE TABLE competitors( competitor_name VARCHAR(45), product_name VARCHAR(45), PRIMARY KEY (competitor_name, product_name) );
That’s the leanest fully-functional schema—only 70-ish lines and ready to run.