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));

Bank account summary II || Leetcode SQL query || Fully-Explained || 💯💯💯✅✅✅🔥🔥🔥

 

                      1587. Bank Account Summary II 👇👇👇


Write an SQL query to report the name and balance of users with a balance higher than 10000. The balance of an account is equal to the sum of the amounts of all transactions involving that account.

Return the result table in any order.

The query result format is in the following example.


Explanation: 
Alice's balance is (7000 + 7000 - 3000) = 11000.
Bob's balance is 1000.
Charlie's balance is (6000 + 6000 - 4000) = 8000.


SQL Solution :-

# Write your MySQL query statement below

# select *
select name,sum(amount) as balance  
from users inner join transactions 
on users.account = transactions.account 
group by name
having balance > 10000; 


Full-Explanation :- 


Appoach: 
  1.  We need to find the name and balance of the tables. 
  2. balance is sum of amount

Query:
  1. firstly, selecting  all  columns (select  * ) 
  2. We apply users inner join transactions satisfying users.account = transactions.account

select *
from users inner join transactions
on users.account = transactions.account



We get :- 

      3.  From this table we group by name then aggregation (sum) is perfomed on amount 
            as balance 
      4.  after aggregation we use having clause to get the name and balance greater than 10000

        
In this way we get the clear output. 







Thank you for reading this solution. 

Happy Learning :) 


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 || 🔥🔥🔥💯💯💯✅✅✅