top of page

MySQL Query Help 2

Updated: Nov 27, 2021

What is MySQL


MySQL, the most popular Open-Source SQL database management system, is developed, distributed, and supported by Oracle Corporation.


MySQL is a database management system


A database is a structured collection of data. It may be anything from a simple shopping list to a picture gallery or the vast amounts of information in a corporate network. To add, access, and process data stored in a computer database, you need a database management system such as MySQL Server.


Since computers are very good at handling large amounts of data, database management systems play a central role in computing, as standalone utilities, or as parts of other applications.


MySQL databases are relational.


A relational database stores data in separate tables rather than putting all the data in one big storeroom. The database structures are organized into physical files optimized for speed. The logical model, with objects such as databases, tables, views, rows, and columns, offers a flexible programming environment.


You set up rules governing the relationships between different data fields, such as one-to-one, one-to-many, unique, required, or optional, and “pointers” between different tables. The database enforces these rules, so that with a well-designed database, your application never sees inconsistent, duplicate, orphan, out-of-date, or missing data.


The SQL part of “MySQL” stands for “Structured Query Language”. SQL is the most common standardized language used to access databases. Depending on your programming environment, you might enter SQL directly (for example, to generate reports), embed SQL statements into code written in another language, or use a language-specific API that hides the SQL syntax.


SQL is defined by the ANSI/ISO SQL Standard. The SQL standard has been evolving since 1986 and several versions exist. In this manual, “SQL-92” refers to the standard released in 1992, “SQL:1999” refers to the standard released in 1999, and “SQL:2003” refers to the current version of the standard. We use the phrase “the SQL standard” to mean the current version of the SQL Standard at any time.


Database for MySQL Practice :

  1. Open MySQL workbench in your system

  2. Select any connection

  3. Enter the following queries in your Editor


Studies table import: -



     CREATE TABLE studies (PNAME varchar(20), INSTITUTE varchar(20), 
     COURSE varchar(20), COURSE_FEE int );
     INSERT INTO studies
     SELECT 'ANAND','SABHARI','PGDCA',4500 UNION ALL
     SELECT 'ALTAF','COIT','DCA',7200 UNION ALL
     SELECT 'JULIANA','BDPS','MCA',22000 UNION ALL
     SELECT 'KAMALA','PRAGATHI','DCA',5000 UNION ALL
     SELECT 'MARY','SABHARI','PGDCA ',4500 UNION ALL
     SELECT 'NELSON','PRAGATHI','DAP',6200 UNION ALL
     SELECT 'PATRICK','PRAGATHI','DCAP',5200 UNION ALL
     SELECT 'QADIR','APPLE','HDCA',14000 UNION ALL
     SELECT 'RAMESH','SABHARI','PGDCA',4500 UNION ALL
     SELECT 'REBECCA','BRILLIANT','DCAP',11000 UNION ALL
     SELECT 'REMITHA','BDPS','DCS',6000 UNION ALL
     SELECT 'REVATHI','SABHARI','DAP',5000 UNION ALL
     SELECT 'VIJAYA','BDPS','DCA',48000


Software table import: -



      CREATE TABLE software (PNAME varchar(20), TITLE 
      varchar(20),DEVELOPIN varchar(20), SCOST decimal(10,2),  DCOST int, 
      SOLD int);
      INSERT INTO software
      SELECT 'MARY','README','CPP',300, 1200, 84 UNION ALL        
      SELECT 'ANAND','PARACHUTES','BASIC',399.95, 6000, 43 UNION ALL
      SELECT 'ANAND','VIDEO TITLING','PASCAL',7500, 16000, 9 UNION ALL
      SELECT 'JULIANA','INVENTORY','COBOL',3000, 3500, 0 UNION ALL
      SELECT 'KAMALA','PAYROLL PKG.','DBASE',9000, 20000, 7 UNION ALL
      SELECT 'MARY','FINANCIAL ACCT.','ORACLE',18000, 85000, 4 UNION ALL
      SELECT 'MARY','CODE GENERATOR','C',4500, 20000, 23 UNION ALL
      SELECT 'PATTRICK','README','CPP',300, 1200, 84 UNION ALL
      SELECT 'QADIR','BOMBS AWAY','ASSEMBLY',750, 3000, 11 UNION ALL       
      SELECT 'QADIR','VACCINES','C',1900, 3100, 21 UNION ALL     
      SELECT 'RAMESH','HOTEL MGMT.','DBASE',13000, 35000, 4 UNION ALL
      SELECT 'RAMESH','DEAD LEE','PASCAL',599.95, 4500, 73 UNION ALL        
      SELECT 'REMITHA','PC UTILITIES','C',725, 5000, 51 UNION ALL
      SELECT 'REMITHA','TSR HELP PKG.','ASSEMBLY',2500, 6000, 7 UNION ALL
      SELECT 'REVATHI','HOSPITAL MGMT.','PASCAL',1100, 75000, 2 UNION ALL
      SELECT 'VIJAYA','TSR EDITOR','C',900, 700, 6



Programmer table import: -




CREATE TABLE programmer (PNAME varchar(20), DOB date, DOJ date, GENDER 
varchar(2), PROF1 varchar(20), PROF2 varchar(20), SALARY int);
INSERT INTO programmer
SELECT 'ANAND','1966-04-12','1992-04-21','M','PASCAL','BASIC',3200 UNION ALL
SELECT 'ALTAF','1964-06-02','1990-11-13','M','CLIPPER','COBOL',2800 UNION ALL         
SELECT 'JULIANA','1960-01-29','1990-04-21','F','COBOL','DBASE',3000 UNION ALL
SELECT 'KAMALA','1968-08-23','1992-01-02','F','C','DBASE',2900 UNION ALL
SELECT 'MARY','1970-06-24','1991-05-01','F','CPP','ORACLE',4500 UNION ALL
SELECT 'NELSON','1985-09-11','1989-08-11','M','COBOL','DBASE',2500 UNION ALL
SELECT 'PATTRICK','1965-11-10','1990-04-21','M','PASCAL','CLIPPER',2800 UNIONALL
SELECT 'QADIR','1965-06-23','1991-04-21','M','ASSEMBLY','C',3000 UNION ALL
SELECT 'RAMESH','1967-03-05','1991-08-22','M','PASCAL','DBASE',3200 UNION ALL
SELECT 'REBECCA','1967-01-01','1990-12-01','F','BASIC','COBOL',2500 UNION ALL
SELECT 'REMITHA','1970-04-08','1993-04-20','F','C','ASSEMBLY',3600 UNION ALL
SELECT 'REVATHI','1969-02-12','1992-01-02','F','PASCAL','BASIC',3700 UNION ALL
SELECT 'VIJAYA','1965-04-14','1992-05-02','F','FOXPRO','C',3500

These queries will import these three tables in your MySQL database


  1. Software

  2. Studies

  3. Programmer


Following are the questions for which you can write the queries in MySQL workbench: -


1) Display THE NUMBER OF packages developed in EACH language.
2) Display THE NUMBER OF packages developed by EACH person.
3) Display THE NUMBER OF male and female programmer.
4) Display THE COSTLIEST packages and HIGEST selling developed in EACH language.
5) Display THE NUMBER OF people BORN in EACH YEAR.
6) Display THE NUMBER OF people JOINED in EACH YEAR.
7) Display THE NUMBER OF people BORN in EACH MONTH.
8) Display THE NUMBER OF people JOINED in EACH MONTH.
9) Display the language wise COUNTS of prof1.
10) Display the language wise COUNTS of prof2.
11) Display THE NUMBER OF people in EACH salary group.
12) Display THE NUMBER OF people who studied in EACH institute.
13) Display THE NUMBER OF people who studied in EACH course.
14) Display the TOTAL development COST of the packages developed in EACH language.
15) Display the selling cost of the package developed in EACH language.
16) Display the cost of the package developed by EACH programmer.
17) Display the sales values of the package developed in EACH programmer.
18) Display the NUMBER of packages developed by EACH programmer.
19) Display the sales COST of packages developed by EACH programmer language wise.
20) Display EACH programmers name, costliest package and cheapest packages developed by Him/Her.
21) Display EACH language name with AVERAGE development cost, AVERAGE cost, selling cost and AVERAGE price per copy.
22) Display EACH institute name with NUMBER of courses, AVERAGE cost per course.
23) Display EACH institute name with NUMBER of students.
24) Display names of male and female programmers.
25) Display the programmer's name and their packages.
26) Display the NUMBER of packages in EACH language.
27) Display the NUMBER of packages in EACH language for which development cost is less than 1000.
28) Display the AVERAGE difference BETWEEN scost and dcost for EACH language.
29) Display the TOTAL scost, dcsot and amount TOBE recovered for EACH programmer for whose dcost HAS NOT YET BEEN recovered.
30) Display highest, lowest and average salaries for THOSE earning MORE than 2000.

Solutions: -


1) Display THE NUMBER OF packages developed in EACH language.

Solution:


 SELECT DEVELOPIN, COUNT(TITLE) FROM SOFTWARE GROUP BY(DEVELOPIN)


2) Display THE NUMBER OF packages developed by EACH person.

Solution:


SELECT PNAME, COUNT(TITLE) FROM SOFTWARE GROUP BY(PNAME)


3) Display THE NUMBER OF male and female programmer.

Solution:


SELECT COUNT(GENDER) AS GENDERCOUNT FROM PROGRAMMER GROUP BY(GENDER)


4) Display THE COSTLIEST packages and HIGEST selling developed in EACH language.

Solution:


SELECT DEVELOPIN, MAX(SCOST) AS COST, MAX(SOLD) AS HIGH FROM SOFTWARE GROUP BY(DEVELOPIN)



If you want a full solution or you want to learn anything then please send help request at contact@codersarts.com or fill the form or Chat with website assistance

Comments


bottom of page