Posts

Featured Post

SQL Interview Success: Unlocking the Top 5 Frequently Asked Queries

Image
 Here are the five top commonly asked SQL queries in the interviews. These you can expect in Data Analyst, or, Data Engineer interviews. Top SQL Queries for Interviews 01. Joins The commonly asked question pertains to providing two tables, determining the number of rows that will return on various join types, and the resultant. Table1 -------- id ---- 1 1 2 3 Table2 -------- id ---- 1 3 1 NULL Output ------- Inner join --------------- 5 rows will return The result will be: =============== 1  1 1   1 1   1 1    1 3    3 02. Substring and Concat Here, we need to write an SQL query to make the upper case of the first letter and the small case of the remaining letter. Table1 ------ ename ===== raJu venKat kRIshna Solution: ========== SELECT CONCAT(UPPER(SUBSTRING(name, 1, 1)), LOWER(SUBSTRING(name, 2))) AS capitalized_name FROM Table1; 03. Case statement SQL Query ========= SELECT Code1, Code2,      CASE         WHEN Code1 = 'A' AND Code2 = 'AA' THEN "A" | "A

How to Write Recursive Shell Script in Bash Terminal

Image
Here's a simple bash recursive function. To write it, you can use JavaScript and other scripting languages. Below is the example that shows you how to write a recursive function in the bash shell. Recursive function Precisely, calling the same function within it is called the Recursive function. We call itself and its contents.  Moreover, the recursive functions go in the loop due to self-calling. While writing the code, ensure it has a condition that breaks the loop. Recursive logic #!/bin/bash for ((i = 1; i < 65; i++)) { ((arr[i - 1] = i)) } i = 1; key = 8 function linear_search { echo "Element value: ${arr[$i-1]}" if ((arr[i - 1] == key)) then echo "Linear search found $key on attempt $i" return 0 => it breaks the loop else ((i++)) linear_search = > Calling th same script fi } linear_search = > Calling the same script Output Here is the dissection of the output. Displayed the array's elements until match-condition occurs. In the end, a displa

How to Call SQL Query from Python

Image
Python's top supported database is MySQL. You can run SQL queries from Python. Here're best examples of how to connect to MYSQL and access MYSQL tables from Python. Read:  How to Print String in Next Line Easily Here are Steps Import MySQL connecter Give user id, password details Issue SQL query Python Logic to import MySQL connector import mysql.connector Note: If the MySQL connecter not installed in python, you need to install it using the below command. pip3 install mysql-connector-python --allow-external mysql-connector-python Supply user id and Password conn=mysql.connector.connect(user='root', password='password', host='localhost', database='sakila') mycursor=conn.cursor() Issue SQL Query mycursor.execute("show tables") # you won't see any result. You need to give print. print(mycursor.fetchall()) mycursor.execute("select * from customer") # you won't see any result. You need to give print. print(mycursor.fetchal

2 Multiline Commenting Ideas in Python

Image
Here are two ways you can comment out multiple lines in python. Python Multiline Comments These are two popular methods Viz Backslash and Triple quote methods. 1. Backslash method >>> s = "This is a test of the emergency broadcast system" \ … " and it will display an emergency if you put a line of text" \ … " that is more than 80 characters on a single line" >>> print(s) This is a test of the emergency broadcast system and it will display an emergency if you put a line of text that is more than 80 characters on a single line 2. Triple quote method >>> s1 = """ This is a test of the emergency broadcast system. … and it will display an emergency if you put a line of text … that is more than 80 characters on a single line … """ >>> print(s1) This is a test of the emergency broadcast system. and it will display an emergency if you put a line of text that is more than 80 characters on a single l

Here is Sample Logic to get Random numbers in Bash

Image
Here's a bash script to generate a random number. You can use this logic to generate a random number, and it is useful for AWS engineers. Random number Script - Here's sample logic to get a random number RANDOM=$$ # Set the seed to the PID of the script UPPER_LIMIT=$1 RANDOM_NUMBER=$(($RANDOM % $UPPER_LIMIT + 1)) echo "$RANDOM_NUMBER" If you select UPPER_LIMIT as 100, then the result would be a pseudo-random number between 1 and 100. Her is the output after executing the script Related posts Structured Vs. Un-structured data

6 Exclusive Differences Between Structured and Unstructured data

Image
Here's a basic interview question for Big data engineers. Why it's basic means many Bachelor degrees now offering courses on Big data, as a beginner, understanding of data is a little tricky. So interviewers stress this point. Don't worry, I made it simplified. So you get a clear concept. I share here a total of six differences between these. In today's world, we have a lot of data. That data is the unstructured format.   Structured Data The major data format is text, which can be string or numeric. The date is also supported. The data model is fixed before inserting the data. Data is stored in the form of a table, making it easy to search. Not easy to scale. Version is maintained as a column in the table. Transaction management and concurrency are easy to support. Unstructured data The data format can be anything from text to images, audio to videos. The data model cannot be fixed since the nature of the data can change. Consider a tweet message that could be text foll

10 Blockchain Smart Contract Interview Questions

Image
Here are the  top ten interview questions  on Blockchain smart contracts. Here you will know about smart-contract, what language and IDE you need to develop. Useful for interviews as well. 1. What is a Smart Contract? A  smart contract  is an executable code on the blockchain intended to digitally facilitate, verify, validate, and enforce the rules and regulations of an application. Smart contracts allow the performance of credible transactions without third parties . These transactions are trackable and irreversible. 2. Where the smart Contract code resides? The smart contract is deployed in a sandbox environment and identified by a 160-bit account address like any other participants on the blockchain network. It executes on the virtual machine (VM) on the blockchain node and is identified by an account number. 3. Smart Contract is it API? Yes, it is like a class. It has methods. These are useful to process transactions in the Blockchain framework. 4. What are the six functions of Sm

How to Explain String Immutability in Python Correctly

Image
Here is an answer to explain the immutability of Strings in Python. It means that you can't modify the string. Due to this, you can use strings securely in many places of your project. How to check string immutability Here is an example. In the python shell, assign a value of your choice to a string. Here my choice is ABCD, and I have assigned it to myString. I have tried to replace A with Z. But, it gave an error due to the immutability of strings. >>> myString = 'ABCD' >>>myString [0] = 'Z' What is learning here The strings immutability is an interview question. In interviews, you can say that strings are immutable, and you can't replace its data. Benefits of strings immutability It saves a lot of time since the data in strings are immutable. It results in high performance. String objects you can reuse as no one can modify its value. Strings are elemental. So no activity can change its value ( these are more like numbers). References Powerful