CREATE TABLE Gaming_Server (
Game char(20),
Game_ID numeric(10),
username char(20),
Platform char(20),
server_location char(20),
primary key(Game_ID));

INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'hacker101', 'BugCrowd', 101011, 'Origin','Asia');

INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'lucifer', 'Fortnite', 101012, 'Steam','Europe');

INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'swift_run', 'Assasins Creed', 101013, 'Ubisoft','East Asia');
INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'eZiO', 'Cyberpunk', 101014, 'Epic Games','West Asia');

INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'runner101', 'doombag',101015, 'Ubisoft','North America');
INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (

'droath', 'Eternal War', 101016, 'Steam','South America');
INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'uchihaMadara', 'PUBG', 101017, 'Tencent','Asia');

INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'naruto01', 'Footgoals', 101018, 'Sony','South America');

INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'DestroyerOp', 'Genshin', 101019, 'Nintendo','Europe');

INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'Hunterrr', 'teenpatti', 101020, 'Steam','Asia');

INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'hawkeye11', 'tekken', 101021, 'Sony','East Asia');

INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'LeviAckerman', 'Shoot Duck', 101022, 'Microsoft','South Asia');
INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'uchihaSasuke', 'Super Mario', 101023, 'Ubisoft','Australia');
INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'theDevil001', 'Diablo', 101024, 'Nexon','Europe');

INSERT INTO Gaming_Server(username, Game, Game_ID, Platform,server_location)
VALUES (
'blackstorm', 'Resident Evil', 101025, 'Steam','Asia');

CREATE TABLE Game_data (
Game char(20),
Game_ID numeric(10),
Revenue numeric(25),
Servers numeric(20),
Game_type char(20),
primary key(Game_ID));

INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'BugCrowd', 101011,'100000','5019283','Skill');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'Fortnite', 101012,'120000000','100000','Action');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'Assasins Creed', 101013,'1200000','100000','Action');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'Cyberpunk', 101014,'3200000','578000','Knowledge');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'doombag',101015,'78309000','910000','adventure');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)

VALUES (
'Eternal War', 101016,'32660000','98000','Arcade');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'PUBG', 101017,'3260090','8810012','Action');

INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'Footgoals', 101018,'791000123','9901833','Sports');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'Genshin', 101019,'91000153','901833','Open World');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'teenpatti', 101020,'892340153','1001900','Strategy');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'tekken', 101021,'993450000','9900000','Action');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'Shoot Duck', 101022,'13400000','8880000','Shooting');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'Super Mario', 101023,'9910000','9123000','Open World');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'Diablo', 101024,'100001200','82903330','Arcade');
INSERT INTO Game_data(Game, Game_ID, Revenue, Servers, Game_type)
VALUES (
'Resident Evil', 101025,'99001200','7891320','Surival');

SELECT * FROM Gaming_Server;
SELECT * FROM Game_data;

SELECT * FROM Gaming_Server;
SELECT MAX(Revenue) as MaxRevenue FROM Game_data;
SELECT MIN(Revenue) as MinRevenue FROM Game_data;
SELECT COUNT(Game_type) as TypesOfGames FROM Game_data;
SELECT SUM(Revenue) as TotalRevenue FROM Game_data;

SELECT Game, Game_ID, Revenue FROM Game_data
ORDER BY Revenue DESC;

SELECT Game, Game_ID, Revenue FROM Game_data
ORDER BY Revenue ASC;

SELECT Game_ID,game_type FROM Game_data WHERE Revenue>901833 GROUP BY Game_ID;

CREATE VIEW top_action_games AS 
SELECT Game_ID, game_type
FROM Game_data
WHERE Revenue > 901833
GROUP BY Game_ID
Having game_type = "Action"; 
SELECT * from top_action_games;

CREATE TABLE gaming_hardware_req (
Game char(20) NOT NULL,
Game_ID numeric(10),
Min_RAM numeric,
Min_storage char(20),
graphics char(20),
primary key(Game_ID),
check (Min_RAM>2),
UNIQUE (Game)
);

CREATE TABLE gaming_software_req (
Game char(20) NOT NULL,
Game_ID numeric(10),
OS char(20),
Connectivity char(20),
BT_version float(10),
primary key(Game_ID),
check (BT_version>4),
UNIQUE (Game)
);

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('Athlete', 101011,100000,'8','RTX 3060');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('BugCrowd', 101001, 3, 5, 'RTX 1640');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('BugCrowde', 101056, 4, 10 ,'RTX 3060');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('Fortnite', 101012, 4 , 4 ,'RTX 1640');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('Assasins Creed', 101013, 4 , 8 ,'RTX 1630');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('Cyberpunk', 101014, 8 , 16 , 'GT 1350' );

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('doombag',101015, 4 ,8,'GT 1360');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('Eternal War', 101016, 6 , 16 ,'RTX 1360');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('PUBG', 101017, 8 , 64 ,'GT 1370');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('Footgoals', 101018, 6 , 128 ,'RTX 1640');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('Genshin', 101019, 8 , 128 ,'GT 1350');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('teenpatti', 101020, 4 , 512 ,'RTX 3060');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('tekken', 101021, 8 , 128 ,'GTX 3010');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('Shoot Duck', 101022, 4 , 64 ,'RTX 1390');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('Super Mario', 101023, 8 , 128 , 'GT 3060');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('Diablo', 101024, 4 , 512,'RTX 3060');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('Resident Evil', 101025, 12 , 128,'GT 3080');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('BugCrowd', 101011, 4.01, 'Windows 8' ,'Ethernet/Wifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('Fortnite', 101012, 4.03 , 'Windows 10' ,'Wifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('Assasins Creed', 101013, 5.1,'Windows 10','Ethernet/Wifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('Cyberpunk', 101014, 4.2 , 'Windows 10' , 'Ethernet/Wifi' );

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('doombag',101015, 4.3 , 'Windows 10' ,'Ethernet/Wifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('Eternal War', 101016, 4.5 , 'Windows 8' ,'Wifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('PUBG', 101017, 5.1 , 'Windows 8' ,'Ethernet/Wifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('Footgoals', 101018, 5.2 , 'Windows 10' ,'Ethernet/Wifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('Genshin', 101019, 4.8 , 'Windows 10' ,'EthernetWifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('teenpatti', 101020, 4.9 , 'Windows 10' ,'Ethernet/Wifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('tekken', 101021, 5.0 , 'Windows 7' ,'Ethernet/Wifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('Shoot Duck', 101022, 4.3 , 'Windows 10' ,'Ethernet/Wifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('Super Mario', 101023, 4.2 , 'Windows 10' , 'Ethernet/Wifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('Diablo', 101024, 4.9 , 'Windows 8','Ethernet/Wifi');

INSERT INTO gaming_software_req(Game, Game_ID,BT_version, OS,
Connectivity)
VALUES ('Resident Evil', 101025, 5.1 , 'Windows 10','Wifi');

INSERT INTO gaming_hardware_req(Game, Game_ID, Min_RAM, Min_storage,
graphics)
VALUES ('BugCrowdee', 1010182, 4, 10 ,'RTX 3060');

SELECT * from gaming_hardware_req;
SELECT * from gaming_software_req;

CREATE VIEW first_view AS
SELECT Game,Game_ID,username FROM gaming_server;
SELECT * from first_view;

 
by

MySQL online editor

Write, Run & Share MySQL queries online using OneCompiler's MySQL online editor and compiler for free. It's one of the robust, feature-rich online editor and compiler for MySQL. Getting started with the OneCompiler's MySQL editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'MySQL' and start writing queries to learn and test online without worrying about tedious process of installation.

About MySQL

MySQL is a open-source, free and very popular relational database management system which is developed, distributed and supported by Oracle corporation.

Key Features:

  • Open-source relational database management systems.
  • Reliable, very fast and easy to use database server.
  • Works on client-server model.
  • Highly Secure and Scalable
  • High Performance
  • High productivity as it uses stored procedures, triggers, views to write a highly productive code.
  • Supports large databases efficiently.
  • Supports many operating systems like Linux*,CentOS*, Solaris*,Ubuntu*,Windows*, MacOS*,FreeBSD* and others.

Syntax help

Commands

1. CREATE

CREATE TABLE table_name (
                column1 datatype,
                column2 datatype,
                ....);

Example

CREATE TABLE EMPLOYEE (
  empId INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  dept TEXT NOT NULL
);

2. ALTER

ALTER TABLE Table_name ADD column_name datatype;

Example

INSERT INTO EMPLOYEE VALUES (0001, 'Dave', 'Sales');

3. TRUNCATE

TRUNCATE table table_name;

4. DROP

DROP TABLE table_name;

5. RENAME

RENAME TABLE table_name1 to new_table_name1; 

6. COMMENT

Single-Line Comments:

 --Line1;

Multi-Line comments:

   /* Line1,
   Line2 */

DML Commands

1. INSERT

INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);

Note: Column names are optional.

Example

INSERT INTO EMPLOYEE VALUES (0001, 'Ava', 'Sales');

2. SELECT

SELECT column1, column2, ...
FROM table_name
[where condition]; 

Example

SELECT * FROM EMPLOYEE where dept ='sales';

3. UPDATE

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition; 

Example

UPDATE EMPLOYEE SET dept = 'Sales' WHERE empId='0001'; 

4. DELETE

DELETE FROM table_name where condition;

Example

DELETE from EMPLOYEE where empId='0001'; 

Indexes

1. CREATE INDEX

  CREATE INDEX index_name on table_name(column_name);
  • To Create Unique index:
  CREATE UNIQUE INDEX index_name on table_name(column_name);

2. DROP INDEX

DROP INDEX index_name ON table_name;

Views

1. Create a View

Creating a View:
CREATE VIEW View_name AS 
Query;

2. How to call view

SELECT * FROM View_name;

3. Altering a View

ALTER View View_name AS 
Query;

4. Deleting a View

DROP VIEW View_name;

Triggers

1. Create a Trigger

CREATE TRIGGER trigger_name trigger_time trigger_event
    ON tbl_name FOR EACH ROW [trigger_order] trigger_body
/* where
trigger_time: { BEFORE | AFTER }
trigger_event: { INSERT | UPDATE | DELETE }
trigger_order: { FOLLOWS | PRECEDES } */

2. Drop a Trigger

DROP TRIGGER [IF EXISTS] trigger_name;

Stored Procedures

1. Create a Stored Procedure

CREATE PROCEDURE sp_name(p1 datatype)
BEGIN
/*Stored procedure code*/
END;

2. How to call Stored procedure

CALL sp_name;

3. How to delete stored procedure

DROP PROCEDURE sp_name;

Joins

1. INNER JOIN

SELECT * FROM TABLE1 INNER JOIN TABLE2 where condition;

2. LEFT JOIN

SELECT * FROM TABLE1 LEFT JOIN TABLE2 ON condition;

3. RIGHT JOIN

SELECT * FROM TABLE1 RIGHT JOIN TABLE2 ON condition;

4. CROSS JOIN

SELECT select_list from TABLE1 CROSS JOIN TABLE2;