c program to clear nth bit of the number || Bitwise Operators || Problem Solving ||

#include <stdio.h> int main() {     int num, n, newNum;     printf("Enter any number: ");     scanf("%d", &num);     printf("Enter nth bit to clear (0-31): ");     scanf("%d", &n);     newNum = num & (~(1 << n));     printf("Number before clearing %d bit: %d (in decimal)\n", n, num);     printf("Number after clearing %d bit: %d (in decimal)\n", n, newNum);     return 0; } Logic :-  num&(~(1<<n));

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_id asc;

Comments

Popular posts from this blog

Merge Strings Alternatively || Leetcode Solution || Easy Approach || Simple || ✅✅✅✅💯💯💯💯🔥🔥🔥🔥

HOW TO PREPARE FOR JEE MAINS IN HOME EFFECTIVELY

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