‘FIELDS TERMINATED BY’ option should be used when the text file which we want to import into MySQL table is having the values which are separated by a comma(, ) or maybe with any other separator like a colon(:), semicolon(;) etc. It can be understood with the help of the following example −ExampleSuppose we are having the following data, separated by a semicolon(;), in the text file ‘A.txt’ which we want to import into a MySQL file −100;Ram;IND;15000 120;Mohan;IND;18000Now with the help of the following query by using the option ‘FIELDS SEPARATED BY ‘we can import the data into MySQL ... Read More
When we run the INSERT INTO statement without giving the columns name/s and values both then MySQL will store NULL as the value of the column/s of table. Consider the example given below in which we have created a table ‘Student’ with the following query −mysql> Create table Student(RollNO INT, Name Varchar(20), Class Varchar(15)); Query OK, 0 rows affected (0.17 sec)Now, we can run INSERT INTO statement without giving the columns name/s and values both as follows −mysql> Insert into Student() Values(); Query OK, 1 row affected (0.02 sec)We can see from the query below MySQL stores NULL as the ... Read More
Suppose currently we are using a tutorial database so it would be the default MySQL database for subsequent queries. Now, with the help of USE db_name statement, we can change the default database to other given database subsequent queries.mysql> USE Sample Database changedThe database has been changed to Sample from the tutorial. To verify this we can run the following command −mysql> select database(); +------------+ | database() | +------------+ | sample | +------------+ 1 row in set (0.00 sec)
In this tutorial, we will be discussing a program to find the numbers from 1 to n that have 4 as a digit.For this we will be provided with a number n. Our task is to count all the numbers which have 4 as one of their digits and print it out.Example Live Demo#include using namespace std; bool has4(int x); //returning sum of digits in the given numbers int get_4(int n){ int result = 0; //calculating the sum of each digit for (int x=1; x
In this tutorial, we will be discussing a program to find the number of even and odd elements in an array.For this we will be provided with an array. Our task is to calculate the number of even and odd elements in the given array.Example Live Demo#include using namespace std; void CountingEvenOdd(int arr[], int arr_size){ int even_count = 0; int odd_count = 0; //looping through the elements for(int i = 0 ; i < arr_size ; i++) { //checking if the number is odd if (arr[i]%2 != 0) odd_count ++ ; else even_count ++ ; } cout
In this tutorial, we will be discussing a program to find the number of increasing sequences.For this we will be provided with an array containing digits 0 to 9. Our task is to count all the sequences present in the array such that the next element is greater than the previous element.Example Live Demo#include using namespace std; //counting the possible subsequences int count_sequence(int arr[], int n){ int count[10] = {0}; //scanning each digit for (int i=0; i=0; j--) count[arr[i]] += count[j]; count[arr[i]]++; } //getting all the possible subsequences int result = 0; for (int i=0; i
In this tutorial, we will be discussing a program to find the number of elements in the array which appears at least K times after their first occurrence.For this we will be provided with an integer array and a value k. Our task is to count all the elements occurring k times among the elements after the element in consideration.Example Live Demo#include #include using namespace std; //returning the count of elements int calc_count(int n, int arr[], int k){ int cnt, ans = 0; //avoiding duplicates map hash; for (int i = 0; i < n; ... Read More
In this tutorial, we will be discussing a program to find the distinct pairs with difference equal to k.For this we will be provided with an integer array and the value k. Our task is to count all the distinct pairs that have the difference as k.Example Live Demo#include using namespace std; int count_diffK(int arr[], int n, int k) { int count = 0; //picking elements one by one for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) if (arr[i] - ... Read More
In this tutorial, we will be discussing a program to find the count of 0s which are blocked by 1s in a binary matrix.For this we will be provided with a binary matrix. Our task is to find and count all the 0s in the matrix that are blocked by 1s.Example Live Demo#include using namespace std; #define Row 4 #define Col 5 int r[4] = { 0, 0, 1, -1 }; int c[4] = { 1, -1, 0, 0 }; bool isSafe(int x, int y, int M[][Col]) { if (x >= 0 && x = 0 && y
In this tutorial, we will be discussing a program to find the 1’s in a sorted binary array.For this we will be provided with an array containing only 1 and 0. Our task is to count the number of 1’s present in the array.Example Live Demo#include using namespace std; //returning the count of 1 int countOnes(bool arr[], int low, int high){ if (high >= low){ int mid = low + (high - low)/2; if ( (mid == high || arr[mid+1] == 0) && (arr[mid] == 1)) return mid+1; ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP