SQLize
Online
/
PHPize Online
/
SQLtest Online
A
A
A
Share
Donate
Blog
Popular
Donate
A
A
A
Share
Blog
Popular
SQLize.online is a free online SQL environment for quickly running, experimenting with and sharing code.
You can run your SQL code on top of the most popular RDBMS including MySQL, MariaDB, SQLite, PostgreSQL, Oracle and Microsoft SQL Server.
SQL code:
Upload
Copy
Format
Clear
Create table UserRole ( RoleId int not null Primary key, Role nvarchar(50) ) Create table Users ( UserSID Int identity (1,1) Primary key, UserID varchar(50) , ManagerSID int foreign key REFERENCES users(UserSID), RoleId Int foreign key REFERENCES UserRole(RoleId), Isactive bit ) insert UserRole (RoleID, Role) values(1,'PM') insert UserRole (RoleID, Role) values(2,'PA') insert UserRole (RoleID, Role) values(3,'PC') insert users select 'User1', NULL,1,1 union select 'User2', NULL,1,1 union select 'User3', NULL,2,1 union select 'User4', NULL,2,1 union select 'User5', NULL,1,1 union select 'User6', NULL,2,1 union select 'User7', NULL,3,1 union select 'User8', NULL,3,1 union select 'User9', NULL,2,1 union select 'User10', NULL,1,1 union select 'User11', NULL,1,1 union select 'User12', NULL,2,1 union select 'User13', NULL,3,1 union select 'User14', NULL,2,1 union select 'User15', NULL,1,1 union select 'User16', NULL,2,1 union select 'User17', NULL,2,1 union select 'User18', NULL,2,1 union select 'User19', NULL,3,1 update Users set managersid = (select usersid from users where userid='user2') where userid = 'user1' update Users set managersid = (select usersid from users where userid='user3') where userid = 'user2' update Users set managersid = (select usersid from users where userid='user4') where userid = 'user3' update Users set managersid = (select usersid from users where userid='user5') where userid = 'user4' update Users set managersid = (select usersid from users where userid='user6') where userid = 'user5' update Users set managersid = (select usersid from users where userid='user7') where userid = 'user6' update Users set managersid = (select usersid from users where userid='user10') where userid = 'user7' update Users set managersid = (select usersid from users where userid='user10') where userid = 'user8' update Users set managersid = (select usersid from users where userid='user10') where userid = 'user9' update Users set managersid = (select usersid from users where userid='user10') where userid = 'user10' select * from userrole select * from Users /* question: write a query to retreive For each role how many users have manager, and how many users don't have manager the output should be like the below: Role UsersWithmanager UsersWithoutmanager PA 4 5 PC 2 2 PM 4 2 */
SQL
Server:
MariaDB 11.4
MariaDB 11.5
MariaDB 10
MariaDB 10 Sakila (ReadOnly)
MySQL 5.7
MySQL 5.7 Sakila (ReadOnly)
MySQL 8.0
MySQL 8.0 Sakila (ReadOnly)
SQLite 3
SQLite 3 Preloaded
PostgreSQL 10 Bookings (ReadOnly)
PostgreSQL 11
PostgreSQL 12
PostgreSQL 13
PostgreSQL 14
PostgreSQL 15
MS SQL Server 2017
MS SQL Server 2019
MS SQL Server 2022
MS SQL Server 2022 AdventureWorks (ReadOnly)
Firebird 4.0
Firebird 4.0 (Employee)
Oracle Database 19c (HR)
Oracle Database 21c
Oracle Database 23c Free
SOQOL
Version
ER Diagram
Preserve result
Stuck with a problem?
Got Error?
Ask ChatGPT!
Result:
Copy
Clear