MySQL Merge Selects Together

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

207 Views

To merge selects together, you need to use GROUP BY clause. To understand the concept, let us create a table. The query to create a table is as follows −mysql> create table MergingSelectDemo    -> (    -> RoomServicesId int,    -> RoomId int,    -> ServiceId int    -> ); Query OK, 0 rows affected (1.98 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into MergingSelectDemo values(10, 10, 10); Query OK, 1 row affected (0.29 sec) mysql> insert into MergingSelectDemo values(20, 10, 20); Query OK, 1 row affected ... Read More

ByteBuffer as LongBuffer Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

110 Views

A view of the ByteBuffer can be created as a LongBuffer using the asLongBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a long buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 50;       try {          ByteBuffer bufferB = ByteBuffer.allocate(n);          LongBuffer bufferL = bufferB.asLongBuffer();       ... Read More

Duration of Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

223 Views

The required duration using a particular temporal unit can be calculated with the method of() in the Duration class in Java. This method requires two parameters i.e. the time value and the temporal unit for that value. It returns the time duration with the particular value and temporal unit.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       long timeValue = 2;     Duration d = Duration.of(timeValue, ChronoUnit.HOURS); System.out.println("The duration in minutes is: ... Read More

Search a Value in Java Tuples Triplet Class

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

94 Views

Use the contains() method to search a value in Triplet class.Let us first see what we need to work with JavaTuples. To work with Triplet class in JavaTuples, you need to import the following package −import org.javatuples.Triplet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Triplet Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Triplet; public class Demo {    public static void main(String[] args) {       Triplet < ... Read More

Calculate Correlation in a MySQL Query

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

2K+ Views

Yes, it is possible to calculate a correlation in a query. To understand the correlation in a query, you need to first create a table. The query to create a table is as followsmysql> create table correlationDemo - > ( - > value float not null, - > value2 float not null - > ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table with the help of insert command. The query is as follows to insert records in the tablemysql> insert into correlationDemo values(1, ... Read More

Instant Parse Method in Java

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

308 Views

The string representation of an Instant can be obtained using the toString() method in the Instant class in Java. This method requires no parameters and it returns the string representation of the Instant.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { Instant i = Instant.now(); System.out.println("The current Instant is: " + i.toString()); } }OutputThe current Instant is: 2019-02-13T09:01:52.484ZNow let us understand the above program.The string representation of the current ... Read More

IntStream filter Method in Java

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

600 Views

The filter() method of the IntStream class in Java returns a stream consisting of the elements of this stream that match the given predicate.The syntax is as follows −IntStream filter(IntPredicate predicate)Here, the predicate parameter is a stateless predicate to apply to each element to determine if it should be included. The IntPredicate above is the predicate of one int-valued argument.Create an IntStream and add elements −IntStream intStream = IntStream.of(20, 34, 45, 67, 89, 100);Now, set a condition and filter stream elements based on it using the filter() method −intStream.filter(a -> a < 50).The following is an example to implement IntStream ... Read More

Copy a Collection from One Database to Another in MongoDB

Smita Kapse
Updated on 30-Jul-2019 22:30:25

2K+ Views

In MongoDB, the command does not exist to copy a collection from one database to another. To achieve it, use the below concept −db.yourCollectionName.find().forEach(function(yourVariableName){    db.getSiblingDB('yourDestinationDatabase')['yourCollectionName'].insert(yourVariableName); });Let us create a collection in the test database and copy this collection to another database with the name „sample‟.To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> use test switched to db test > db.copyThisCollectionToSampleDatabaseDemo.insertOne({"User_Id":101, "UserName":"Larr y"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c77ad622386c62d05142a67") } > db.copyThisCollectionToSampleDatabaseDemo.insertOne({"User_Id":102, "UserName":"Maxwell"}); {    "acknowledged" : true,   ... Read More

PHP Equivalent of MySQL's UNHEX Function

Samual Sam
Updated on 30-Jul-2019 22:30:25

637 Views

You can use hex2bin() function since it is the PHP equivalent of MySQL's UNHEX().The syntax is as follows −$anyVariableName = hex2bin("yourHexadecimalValue");To understand the above syntax, let us implement the above syntax in PHP. The PHP code is as follows −$myFirstValue = hex2bin("7777772E4D7953514C4578616D706C652E636F6D"); var_dump($myFirstValue); $mySecondValue=hex2bin("416476616E6365644A617661576974684672616D65776F726B"); echo(''); var_dump($mySecondValue);The snapshot of PHP code is as follows −Here is the snapshot of The output −Here is the MySQL UNHEX() −Case 1 − The query is as follows −mysql> SELECT UNHEX("7777772E4D7953514C4578616D706C652E636F6D");The following is The output −+---------------------------------------------------+ | UNHEX("7777772E4D7953514C4578616D706C652E636F6D") | +---------------------------------------------------+ | www.MySQLExample.com ... Read More

Namespace in C++

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

247 Views

Consider a situation, when we have two persons with the same name, Zara, in the same class. Whenever we need to differentiate them definitely we would have to use some additional information along with their name, like either the area, if they live in different area or their mother’s or father’s name, etc.Same situation can arise in your C++ applications. For example, you might be writing some code that has a function called xyz() and there is another library available which is also having same function xyz(). Now the compiler has no way of knowing which version of xyz() function ... Read More

Advertisements