Create table companymast (compid int, compname varchar (10); Create table itemmast…
- User
Create table company_mast (comp_id int, comp_name varchar (10); Create table item_mast (prod_ id int, prod_name varchar (16), prod_price,prod_comp);
- Assistant
CREATE TABLE company_mast ( comp_id INT, comp_name VARCHAR(10) );
CREATE TABLE item_mast ( prod_id INT, prod_name VARCHAR(16), prod_price DECIMAL, prod_comp INT );
- User
insert into company_mast values 11 Samsung 12 iBall 13 Epsion 14 Zebronics 15 Asus 16 Frontech
- Assistant
INSERT INTO company_mast (comp_id, comp_name) VALUES (11, 'Samsung'); INSERT INTO company_mast (comp_id, comp_name) VALUES (12, 'iBall'); INSERT INTO company_mast (comp_id, comp_name) VALUES (13, 'Epsion'); INSERT INTO company_mast (comp_id, comp_name) VALUES (14, 'Zebronics'); INSERT INTO company_mast (comp_id, comp_name) VALUES (15, 'Asus'); INSERT INTO company_mast (comp_id, comp_name) VALUES (16, 'Frontech');
- User
insert into company_mast values ('11','Samsung'); ('12','iBall'); ('13','Epsion'); ('14','Zebronics'); ('15','Asus'); ('16','Frontech');
- Assistant
INSERT INTO company_mast (comp_id, comp_name) VALUES ('11', 'Samsung'), ('12', 'iBall'), ('13', 'Epsion'), ('14', 'Zebronics'), ('15', 'Asus'), ('16', 'Frontech');
- User
insert into item_mast values PRO_ID PRO_NAME PRO_PRICE PRO_COM
101 Mother Board 3200.00 15 102 Key Board 450.00 16 103 ZIP drive 250.00 14 104 Speaker 550.00 16 105 Monitor 5000.00 11 106 DVD drive 900.00 12 107 CD drive 800.00 12 108 Printer 2600.00 13 109 Refill cartridge 350.00 13 110 Mouse 250.00 12 - Assistant
INSERT INTO item_mast (prod_id, prod_name, prod_price, prod_comp) VALUES (101, 'Mother Board', 3200.00, 15), (102, 'Key Board', 450.00, 16), (103, 'ZIP drive', 250.00, 14), (104, 'Speaker', 550.00, 16), (105, 'Monitor', 5000.00, 11), (106, 'DVD drive', 900.00, 12), (107, 'CD drive', 800.00, 12), (108, 'Printer', 2600.00, 13), (109, 'Refill cartridge', 350.00, 13), (110, 'Mouse', 250.00, 12);
- User
From the following tables write a SQL query to calculate the average price of each manufacturer's product along with their name. Return Average Price and Company.
- Assistant
SELECT cm.comp_name AS Company, AVG(im.prod_price) AS Average_Price FROM company_mast cm INNER JOIN item_mast im ON cm.comp_id = im.prod_comp GROUP BY cm.comp_name;
- User
From the following tables write a SQL query to calculate the average price of each manufacturer's product of 350 or more. Return Average Price and Company.
- Assistant
SELECT cm.comp_name AS Company, AVG(im.prod_price) AS Average_Price FROM company_mast cm INNER JOIN item_mast im ON cm.comp_id = im.prod_comp WHERE im.prod_price >= 350 GROUP BY cm.comp_name;
- User
From the following tables, write a SQL query to find the most expensive product of each company. Return Product Name, Price and Company.
- Assistant
SELECT cm.comp_name AS Company, im.prod_name AS Product_Name, im.prod_price AS Price FROM company_mast cm INNER JOIN item_mast im ON cm.comp_id = im.prod_comp WHERE im.prod_price = ( SELECT MAX(prod_price) FROM item_mast WHERE prod_comp = cm.comp_id ) GROUP BY cm.comp_name;
- User
Create table emp_department (DPT_CODE ,DPT_NAME,DPT_ALLOTMENT);
- Assistant
CREATE TABLE emp_department ( DPT_CODE INT, DPT_NAME VARCHAR(50), DPT_ALLOTMENT DATE );
- User
insert into emp_department 57 IT 65000 63 Finance 15000 47 HR 240000 27 RD 55000 89 QC 75000
- Assistant
INSERT INTO emp_department (DPT_CODE, DPT_NAME, DPT_ALLOTMENT) VALUES (57, 'IT', '65000'), (63, 'Finance', '15000'), (47, 'HR', '240000'), (27, 'RD', '55000'), (89, 'QC', '75000');
- User
what do I use on mysql if allontment is this instead of date 15000
- Assistant
If the DPT_ALLOTMENT column is not of the DATE data type and you want to store the value '15000' as a numeric value, you would use the DECIMAL or INT data type for the column. Here's an example of how to create the table with the DPT_ALLOTMENT column as DECIMAL:
CREATE TABLE emp_department ( DPT_CODE INT, DPT_NAME VARCHAR(50), DPT_ALLOTMENT DECIMAL(10, 2) );
And to insert the values into the table:
INSERT INTO emp_department (DPT_CODE, DPT_NAME, DPT_ALLOTMENT) VALUES (57, 'IT', 15000.00), (63, 'Finance', 15000.00), (47, 'HR', 240000.00), (27, 'RD', 55000.00), (89, 'QC', 75000.00);
- User
create table emp_details EMP_IDNO, EMP_FNAME,EMP_LNAME,EMP_DEPT);
- Assistant
CREATE TABLE emp_details ( EMP_IDNO INT, EMP_FNAME VARCHAR(50), EMP_LNAME VARCHAR(50), EMP_DEPT VARCHAR(50) );
- User
insert into emp_details 127323 Michale Robbin 57 526689 Carlos Snares 63 843795 Enric Dosio 57 328717 Jhon Snares 63 444527 Joseph Dosni 47 659831 Zanifer Emily 47 847674 Kuleswar Sitaraman 57 748681 Henrey Gabriel 47 555935 Alex Manuel 57 539569 George Mardy 27 733843 Mario Saule 63 631548 Alan Snappy 27 839139 Maria Foster 57
- Assistant
INSERT INTO emp_details (EMP_IDNO, EMP_FNAME, EMP_LNAME, EMP_DEPT) VALUES (127323, 'Michale', 'Robbin', '57'), (526689, 'Carlos', 'Snares', '63'), (843795, 'Enric', 'Dosio', '57'), (328717, 'Jhon', 'Snares', '63'), (444527, 'Joseph', 'Dosni', '47'), (659831, 'Zanifer', 'Emily', '47'), (847674, 'Kuleswar', 'Sitaraman', '57'), (748681, 'Henrey', 'Gabriel', '47'), (555935, 'Alex', 'Manuel', '57'), (539569, 'George', 'Mardy', '27'), (733843, 'Mario', 'Saule', '63'), (631548, 'Alan', 'Snappy', '27'), (839139, 'Maria', 'Foster', '57');
- User
From the following tables write a SQL query to find employees whose last name is Gabriel or Dosio. Return emp_idno, emp_fname, emp_lname and emp_dept.
- Assistant
SELECT EMP_IDNO, EMP_FNAME, EMP_LNAME, EMP_DEPT FROM emp_details WHERE EMP_LNAME IN ('Gabriel', 'Dosio');
- User
From the following tables write a SQL query to find those employees who work for the department where the departmental allotment amount is more than Rs. 50000. Return emp_fname and emp_lname.
- Assistant
SELECT emp_fname, emp_lname FROM emp_details WHERE EMP_DEPT IN ( SELECT DPT_CODE FROM emp_department WHERE DPT_ALLOTMENT > 50000 );
- User
From the following tables write a SQL query to find the departments whose sanction amount is higher than the average sanction amount for all departments. Return dpt_code, dpt_name and dpt_allotment.
- Assistant
SELECT DPT_CODE, DPT_NAME, DPT_ALLOTMENT FROM emp_department WHERE DPT_ALLOTMENT > ( SELECT AVG(DPT_ALLOTMENT) FROM emp_department );
- User
From the following tables write a SQL query to find which departments have more than two employees. Return dpt_name.
- Assistant
SELECT DPT_NAME FROM emp_department WHERE DPT_CODE IN ( SELECT EMP_DEPT FROM emp_details GROUP BY EMP_DEPT HAVING COUNT(*) > 2 );