sql interview question on sum()
ฝัง
- เผยแพร่เมื่อ 26 พ.ย. 2024
- create table scm_suppliers(
supplier_id int primary key,
supplier_name varchar2(50) not null,
contact_name varchar2(50),
phone varchar2(15)
);
create table scm_products(
product_id int primary key,
product_name varchar2(50) not null,
supplier_id int,
unit_price decimal(10,2),
foreign key (supplier_id) references scm_suppliers(supplier_id)
);
create table scm_warehouses(
warehouse_id int primary key,
warehouse_name varchar2(100) not null,
location varchar2(100)
);
create table scm_inventory(
inventory_id int primary key,
product_id int,
warehouse_id int,
quantity int,
foreign key (product_id) references scm_products(product_id),
foreign key (warehouse_id) references scm_warehouses(warehouse_id)
);
begin
insert into scm_suppliers (supplier_id, supplier_name, contact_name, phone)
values (1, 'Supplier A', 'John Doe', '123-456-7890');
insert into scm_suppliers (supplier_id, supplier_name, contact_name, phone)
values (2, 'Supplier B', 'Jane Smith', '987-654-3210');
insert into scm_products (product_id, product_name, supplier_id, unit_price)
values (1, 'Product 1', 1, 10.50);
insert into scm_products (product_id, product_name, supplier_id, unit_price)
values (2, 'Product 2', 1, 20.00);
insert into scm_products (product_id, product_name, supplier_id, unit_price)
values (3, 'Product 3', 2, 15.75);
insert into scm_warehouses (warehouse_id, warehouse_name, location)
values (1, 'Warehouse 1', 'New York');
insert into scm_warehouses (warehouse_id, warehouse_name, location)
values (2, 'Warehouse 2', 'Los Angeles');
insert into scm_warehouses (warehouse_id, warehouse_name, location)
values (3, 'Warehouse 3', 'Chicago');
insert into scm_inventory (inventory_id, product_id, warehouse_id, quantity)
values (1, 1, 1, 100);
insert into scm_inventory (inventory_id, product_id, warehouse_id, quantity)
values (2, 1, 2, 200);
insert into scm_inventory (inventory_id, product_id, warehouse_id, quantity)
values (3, 2, 1, 50);
insert into scm_inventory (inventory_id, product_id, warehouse_id, quantity)
values (4, 2, 3, 150);
insert into scm_inventory (inventory_id, product_id, warehouse_id, quantity)
values (5, 3, 3, 120);
end;
/