Posts

Showing posts with the label MySql

C++ || STL || standard template libraries

Image
                                       C++ STL  1.      Pair :  Syntax :      pair <int,char> p1;     it creates a pair {2,'c'} like this.           pair <int,int> p2;     it creates a pair {2,3} like this .  Basic Code :  #include <bits/stdc++.h> using namespace std; int main() {     // cout<<"hello world\n";     pair <int,int> p1 = {1,2};     cout<<p1.first<< " "<< p1.second<<endl;          pair <int, pair<int ,char>> p2 = {1,{2,'c'}};     cout<<p2.first<<" "<<p2.second.first<<" "<<p2.second.second<<endl;          pair <int,int> arr[] = {{2,3},{4,5},{6,7}};     cout...

DDL commands (Data Definition Language)

  DATA DEFINITION LANGUAGE :  1. permanently saves all the changes in the table  Examples:  1. Create  2. Alter  3. Drop  4. Truncate  1. Create :-  Creates the new table permanently in the database  2. Alter :- 

1978. Employees Whose Manager Left the Company || Leetcode SQL solution || simple sql query || 🔥🔥🔥💯💯💯✅✅✅

Image
  Employees whose manages left their company : 👇👇👇💯  Leetcode Solution:--  Intuition To find the manager who left the company, whose salary is less than 30000 dollars Approach step 1:  filter the rows whose salary is strictly less than $30000 select * from employees where salary <= 30000   Here manager_id = 6 left the company (because it isn't in employee_id column) step 2:  we need to find the manager how left the company. This we can find by searching it in employee_id from employees table (with a sub query ). select employee_id from employees where salary <= 30000 and manager_id not in ( select employee_id from employees ) step 3:  we need to order the table by employee_id. Code # Write your MySQL query statement below select employee_id from employees where salary <= 30000 and manager_id not in ( select employee_id from employees ) order by employee_id ; Please go through my blog and find more so...

Percentage of users attending the contest || Leetcode solution || simple explanation ||💯💯💯💯✅✅✅🔥🔥🔥🔥

                                1633 .   Percentage of Users Attended a Contest Problem:- To find the percentage of users attending contest from users and register table  Link for question :-  click here so we need to use group by contest_id then aggregation is performed on count(register.user_id) Approach select count ( * ) from users This will get the total count of the table in users is 3. count ( register . user_id ) At first group by is done on contest_id (multiple rows to single row) and aggregation is done on count(register.user_id) SQL Solution :-  # Write your MySQL query statement below select register . contest_id , round ( count ( register . user_id ) * 100 / ( select count ( * ) from users ) , 2 ) as percentage from users inner join register on users . user_id = register . user_id group by contest_id order by percentage desc , contest...