Anvi Jain has Published 568 Articles

How to calculate value from multiple columns in MySQL?

Anvi Jain

Anvi Jain

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

1K+ Views

To calculate a value from multiple columns, use GROUP BY. Following is the syntax −select yourColumnName1, sum(yourColumnName2*yourColumnName3) AS anyAliasName from yourTableName group by yourColumnName1;Let us first create a table −mysql> create table calculateValueDemo    -> (    -> Id int,    -> ProductPrice int,    -> ProductWeight int    -> ... Read More

The collection.find() always returns all fields with MongoDB?

Anvi Jain

Anvi Jain

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

600 Views

You can return a specific field from collection.find() by using the following syntax.Case 1 − The syntax is as follows −db.yourCollectionName.find({}, {"yourFieldName":1}).pretty();The above field name is set to 1 means it will return only that field. If you set to 0 it will return all fields except the field which ... Read More

C++ Program to Construct Transitive Closure Using Warshall’s Algorithm

Anvi Jain

Anvi Jain

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

931 Views

If a directed graph is given, determine if a vertex j is reachable from another vertex i for all vertex pairs (i, j) in the given graph. Reachable mean that there is a path from vertex i to j. This reach-ability matrix is called transitive closure of a graph. Warshall ... Read More

How to use the CAST function in a MySQL SELECT statement?

Anvi Jain

Anvi Jain

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

400 Views

The CAST() function in MySQL converts a value of any type into a value that has a specified type. Let us first create a table −mysql> create table castFunctionDemo    -> (    -> ShippingDate date    -> ); Query OK, 0 rows affected (0.74 sec)Following is the query to ... Read More

C++ Program to Implement Traveling Salesman Problem using Nearest Neighbour Algorithm

Anvi Jain

Anvi Jain

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

1K+ Views

Here is a C++ Program to Implement Traveling Salesman Problem using Nearest Neighbour Algorithm.Required functions and pseudocodesAlgorithmBegin    Initialize c = 0, cost = 1000;    Initialize g[][].    function swap() is used to swap two values x and y.    function cal_sum() to calculate the cost which take array ... Read More

MySQL format time with lowercase am/pm?

Anvi Jain

Anvi Jain

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

769 Views

To format MySQL time with lowercase am/pm, use the LOWER() as well as DATE_FORMAT().Let us first create a table −mysql> create table formatTime    -> (    -> LoginTime time    -> ); Query OK, 0 rows affected (0.56 sec)Following is the query to insert records in the table using ... Read More

C++ program to Check if a Given Binary Tree is an AVL Tree or Not

Anvi Jain

Anvi Jain

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

2K+ Views

AVL tree is a self-balancing Binary Search Tree where the difference between heights of left and right subtrees cannot be more than one for all nodes.This is a C++ program to check if a given Binary Tree is an AVL Tree or not.AlgorithmBegin function AVL() returns true if the given ... Read More

Reorder integer except for value 0 with MySQL?

Anvi Jain

Anvi Jain

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

113 Views

To reorder integer except for value 0, use the below syntax −select *from yourTableName order by yourColumnName=0 ,yourColumnName;Let us first create a table −mysql> create table reorderIntegerExcept0    -> (    -> value int    -> ); Query OK, 0 rows affected (0.70 sec)Following is the query to insert records ... Read More

How to generate different random numbers in a loop in C++?

Anvi Jain

Anvi Jain

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

4K+ Views

Let us see how to generate different random numbers using C++. Here we are generating random numbers in range 0 to some value. (In this program the max value is 100).To perform this operation we are using the srand() function. This is in the C++ library. The function void srand(unsigned ... Read More

C++ Program to Apply Above-Below-on Test to Find the Position of a Point with respect to a Line

Anvi Jain

Anvi Jain

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

599 Views

This is a C++ program to apply Above-Below-on Test to find the position of a point with respect to a Line. For any point t (xt, yt) on the plane, its position with respect to the line L connecting m and n is found by calculating the scalar s −Y ... Read More

Advertisements