Get Previous Day with MySQL CURDATE

Kumar Varma
Updated on 30-Jul-2019 22:30:26

348 Views

Let us first get the current date using CURDATE(). The current date is as follows −mysql> select CURDATE(); +------------+ | CURDATE() | +------------+ | 2019-06-09 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ShippingDate date    -> ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command. While inserting, we have used date_sub to get the previous day −mysql> insert into DemoTable(ShippingDate) values(date_sub(CURDATE(), interval 1 day)); Query OK, 1 row ... Read More

C++ Program for Range Sum Queries Without Updates

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

363 Views

Here we will see how to get the sum of elements from index i to index j in an array. This is basically the range query. The task is easy by just running one loop from index i to j, and calculate the sum. But we have to care about that this kind of range query will be executed multiple times. So if we use the mentioned method, it will take much time. To solve this problem using more efficient way we can get the cumulative sum at first, then the range sum can be found in constant time. Let ... Read More

Size of int and long Type as per C++ Standard

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

653 Views

Here we will see what are the sizes of the int and long type data in C++. The sizes are depending on the system architecture and the Operating system.So in the 32-bit system, the standard is ILP32. In this standard the int, long and the pointer variables are of 32-bits.For the 64-bit system there are two variations. For Linux Operating system the standard is LP64. Here long and pointer are of 64-bits, but int are of 32-bits. For the Windows operating system, the standard is LLP64. Here long long is 64-bit, but int and long are of 32-bits.Example#include using ... Read More

Bit Map Protocol

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

4K+ Views

Bit-map protocol is a collision free protocol that operates in the Medium Access Control (MAC) layer of the OSI model. It resolves any possibility of collisions while multiple stations are contending for acquiring a shared channel for transmission.In this protocol, if a station wishes to transmit, it broadcasts itself before the actual transmission. This is an example of Reservation Protocol.Working PrincipleIn this protocol, the contention period is divided into N slots, where N is the total number of stations sharing the channel. If a station has a frame to send, it sets the corresponding bit in the slot.Suppose that there ... Read More

Clear Android Notification If Activity Crashes

Anvi Jain
Updated on 30-Jul-2019 22:30:26

265 Views

This example demonstrate about How to clear an Android notification if activity crashesStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.package app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Intent ; import android.os.Bundle ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; public class MainActivity extends AppCompatActivity {    public static final String NOTIFICATION_CHANNEL_ID = "10001" ;    private ... Read More

Search Documents by Adding Two Properties in MongoDB

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

134 Views

You can use aggregate framework for this. Here, we will get the sum and then match it to search for documents less than a particular number. Let us first create a collection with documents −> db.searchDocumentsDemo.insertOne({"Value1":100, "Value2":560}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3fe1eedc6604c74817ce9") } > db.searchDocumentsDemo.insertOne({"Value1":300, "Value2":150}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3fe29edc6604c74817cea") } > db.searchDocumentsDemo.insertOne({"Value1":400, "Value2":200}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3fe30edc6604c74817ceb") } > db.searchDocumentsDemo.insertOne({"Value1":190, "Value2":210}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3fe45edc6604c74817cec") }Following is the query to display all documents from a collection with the help of ... Read More

Insert Current Date Plus Specific Time in MySQL

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

471 Views

You can use CONCAT() for this. The syntax is as follows −insert into DemoTable values(concat(curdate(), ' yourSpecificTime’));Let us first create a table −mysql> create table DemoTable    (    ArrivalDate datetime    ); Query OK, 0 rows affected (1.06 sec)Insert some records in the table using insert command. We are adding the current date and time −mysql> insert into DemoTable values(concat(curdate(), ' 10:20:05')); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(concat(curdate(), ' 12:05:00')); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+---------------------+ | ArrivalDate ... Read More

Batch Inserts Using JDBC Statements

Anvi Jain
Updated on 30-Jul-2019 22:30:26

409 Views

Grouping a set of INSERT Statements and executing them at once is known as batch insert.Batch inserts using Statement objectTo execute a batch of insert statements using the Statement object −Add statements to the batch − Prepare the INSERT quires one by one and add them to batch using the addBatch() method of the Statement Interface as shown below −String insert1 = Insert into table_name values(value1, value2, value3, ......); stmt.addBatch(insert1); String insert2 = Insert into table_name values(value1, value2, value3, ......); stmt.addBatch(insert2); String insert3 = Insert into table_name values(value1, value2, value3, ......); stmt.addBatch(insert3);Execute the batch − After adding the required statements, ... Read More

Set 0 for Null Values in MySQL Query

Rama Giri
Updated on 30-Jul-2019 22:30:26

882 Views

For this, you can use IFNULL(). Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Value int    -> ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values(100); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Value) values(140); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Value) values(200); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable(Value) values(450); Query OK, 1 row affected (0.13 ... Read More

C++ Program for Recursive Bubble Sort

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

1K+ Views

In this section we will see another approach of famous bubble sort technique. We have used bubble sort in iterative manner. But here we will see recursive approach of the bubble sort. The recursive bubble sort algorithm is look like this.AlgorithmbubbleRec(arr, n)begin    if n = 1, return    for i in range 1 to n-2, do       if arr[i] > arr[i+1], then          exchange arr[i] and arr[i+1]       end if    done    bubbleRec(arr, n-1) endExample Live Demo#include using namespace std; void recBubble(int arr[], int n){    if (n == 1)     ... Read More

Advertisements