Hero Motocorp SQL Interview Questions using REPLICATE(), RIGHT() and CONCAT() Functions

  Рет қаралды 3,347

Cloud Challengers

Cloud Challengers

Күн бұрын

SQL questions recently asked in Motocorp interview.
1. We need to mask first 12 digits of card number.
2. Need to select employee names with same salary.
Create table syntax
CREATE TABLE cards (card_number BIGINT)
INSERT INTO cards VALUES (1234567812345678),(2345678923456789),(3456789034567890)
CREATE TABLE Employee (employee_id INT,ename VARCHAR(50),salary INT)
INSERT INTO Employee VALUES (3, 'Bob', 60000),(4, 'Diana', 70000),(5, 'Eve', 60000),(6, 'Frank', 80000),(7, 'Grace', 70000),(8, 'Henry', 90000)
For more SQL interview questions. Check out our playlist.
• SQL Interview Questions
Contact us:
info@cloudchallengers.com
Follow us on
Instagram : cloudchallengers
Facebook : cloudchallengers
LinkedIn : linkedin.com/company/cloudchallengers

Пікірлер: 26
@abhishekkrpaul
@abhishekkrpaul 27 күн бұрын
2. SELECT ename FROM employee WHERE salary IN (SELECT salary FROM employee GROUP BY salary HAVING count(*) >1)
@Harini-x7t
@Harini-x7t Ай бұрын
Q1 with cte as( select salary,count(*) as cnt from EP group by salary having count(*) > 1 ) select ename from EP where salary in ( select salary from cte ) Q2 select card_number, replicate('*',12) + RIGHT(cast(card_number as varchar(20)),4) as card_no from cards
@CloudChallengers
@CloudChallengers Ай бұрын
@Harini-x7t, Thanks for sharing the alternative approach
@shyamshivakumar7807
@shyamshivakumar7807 Ай бұрын
1) select concat(repeat("*",length(card_number)-4),substr(card_number,length(card_number)-3,length(card_number))) as new_card_number from cards 2) with cte as ( select *, count(salary) over(partition by salary) as cnt from emp_que) select employee_id,ename from cte where cnt!=1
@sravankumar1767
@sravankumar1767 Ай бұрын
Superb explanation 👌 👏 👍
@srinivasulum414
@srinivasulum414 Ай бұрын
with cte as ( select *,count(*)over( partition by salary )As rno from Employee ) select ename from cte where rno>1
@dasubabuch1596
@dasubabuch1596 Ай бұрын
1) select lpad(substr(card_number,13,14),16,'*'), card_number from cards; 2) with t as ( select salary, count(*) from employees group by salary having count(*) >=2 ), t1 as ( select ename from employees where salary in (select salary from t) ) select * from t1;
@pallavimohapatra7241
@pallavimohapatra7241 Ай бұрын
1. select repeat('*', 12) || SUBSTRING(card_number::text FROM 12 + 1) as card_number from cards 2. with cte as(select ename, count(salary) over(partition by salary) as cnt from Employee) select ename from cte where cnt != 1
@entertainmenthub5066
@entertainmenthub5066 Ай бұрын
Great Job Sir Ji
@pravinshinde1891
@pravinshinde1891 19 күн бұрын
select lpad('*',12,'*')||''||rpad(CARD_NUMBER,4) as card_number from cards
@pavankumarreddy7866
@pavankumarreddy7866 29 күн бұрын
select REPLICATE('*',12)+RIGHT(card_number,4) as new from cards
@pritambanerjee6957
@pritambanerjee6957 Ай бұрын
Q1 SELECT REPLACE(card_number,SUBSTRING(card_number,1,12),REPEAT("*",LENGTH(SUBSTRING(card_number,1,12)))) AS masked_card_number FROM cards; Q2 SELECT ename FROM Employee WHERE salary IN( SELECT salary FROM Employee GROUP BY salary HAVING COUNT(ename) > 1);
@Sachin_Sambare
@Sachin_Sambare Ай бұрын
1st Oue. Solution in Oracle SQL - SELECT CARD_NUMBER,REGEXP_REPLACE(SKP,'[^*]','')||MM AS NEW_CARD FROM ( SELECT C.*,LPAD(CARD_NUMBER,28,'*') AS SKP,SUBSTR(CARD_NUMBER,-4) AS MM FROM CARDS C);
@sravankumar1767
@sravankumar1767 Ай бұрын
SELECT CASE WHEN LEN(column_name) > 12 THEN REPLICATE('X', 12) + RIGHT(column_name, LEN(column_name) - 12) ELSE REPLICATE('X', LEN(column_name)) END AS masked_column FROM table_name;
@CloudChallengers
@CloudChallengers Ай бұрын
@sravankumar1767, Thanks for sharing the different approach
@sravankumar1767
@sravankumar1767 Ай бұрын
SELECT ename FROM employees WHERE salary IN ( SELECT salary FROM employees GROUP BY salary HAVING COUNT(*) > 1 ) ORDER BY salary;
@CloudChallengers
@CloudChallengers Ай бұрын
@sravankumar1767, Thanks for sharing the different approach
@chandanpatra1053
@chandanpatra1053 Ай бұрын
please cover all the hackerrank medium & advanced level questions.If possible start a new series called "Hackerrank" series video
@CloudChallengers
@CloudChallengers Ай бұрын
@chandanpatra1053, Definitely, I will be working on this in future.
@shraddhadhakad1154
@shraddhadhakad1154 Ай бұрын
SELECT *, CONCAT(REPEAT('*', 4) ,RIGHT(CARD_NUMBER,4))as new_Cardnumber FROM cards;
@hairavyadav6579
@hairavyadav6579 Ай бұрын
My Approach select c1.* from cards c1 join cards c2 on c1.salary = c2.salary where c1.employee_id != c2.employee_id;
@june17you
@june17you Ай бұрын
Can you please share the query for masking in MySQL as well? I tried the same but it's not working. Thank you
@CloudChallengers
@CloudChallengers Ай бұрын
SELECT card_number, CONCAT(REPEAT('*', LENGTH(card_number) - 4), RIGHT(card_number, 4)) AS newcard_number FROM cards You can try this
@suprisahana
@suprisahana 28 күн бұрын
Can you share the query for oracle database, as we don’t have replica keyword in Oracle.
@CloudChallengers
@CloudChallengers 26 күн бұрын
SELECT card_number, CONCAT(LPAD('', LENGTH(card_number) - 4, '*'),SUBSTR(card_number, -4)) AS newcard_number FROM cards Try this
KPMG SQL Interview Question - Using ROW_NUMMBER( ) & CASE Statement
8:15
Cloud Challengers
Рет қаралды 2,3 М.
The Joker kisses Harley Quinn underwater!#Harley Quinn #joker
00:49
Harley Quinn with the Joker
Рет қаралды 43 МЛН
Or is Harriet Quinn good? #cosplay#joker #Harriet Quinn
00:20
佐助与鸣人
Рет қаралды 48 МЛН
Infosys SQL Interview Question
9:23
Cloud Challengers
Рет қаралды 4,3 М.
Postgres just got even faster
26:42
Hussein Nasser
Рет қаралды 14 М.
The 25 SQL Questions You MUST Know for Data Analyst Interviews
32:47
KSR Datavizon
Рет қаралды 219 М.
WIPRO SQL Interview Question - FIRST_VALUE( ) Function
11:18
Cloud Challengers
Рет қаралды 11 М.
BOSCH SQL Interview Question - FIRST_VALUE() WINDOWS Function
9:23
Cloud Challengers
Рет қаралды 6 М.
Ecolab SQL Interview Question - SUBSTRING() and CHARINDEX() Functions
9:57
Cloud Challengers
Рет қаралды 2,8 М.