Count Specific Comma-Separated Values in MySQL Database Row

AmitDiwan
Updated on 04-Oct-2019 06:38:12

493 Views

To count comma-separated-values, use aggregate function COUNT(*) along with FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable (    Value varchar(100) ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('10, 20, 60, 80'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('60, 70, 90'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('50, 55, 65, 60'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('90, 98, 97'); Query OK, 1 row affected (0.12 sec)Display all records ... Read More

SUBSTR_REPLACE Function in MySQL

AmitDiwan
Updated on 04-Oct-2019 06:36:38

174 Views

For this, use the INSERT() function from MySQL. The INSERT(str, pos, len, newstr) returns the string str, with the substring beginning at position pos and len characters long replaced by the string newstr. Returns the original string if pos is not within the length of the string.It replaces the rest of the string from position pos if len is not within the length of the rest of the string. Returns NULL if any argument is NULL.Let us first create a table −mysql> create table DemoTable (    Password varchar(50) ); Query OK, 0 rows affected (0.51 sec)Insert some records in ... Read More

Implement MySQL Conditional GROUP BY with NOT IN

AmitDiwan
Updated on 04-Oct-2019 06:34:01

115 Views

Let us first create a table −mysql> create table DemoTable (    Name varchar(40),    Score int ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam', 89); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Adam', 89); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Chris', 89); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Chris', 89); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Bob', 98); Query OK, 1 row affected (0.10 sec) mysql> insert ... Read More

Find Highest Average Marks of Students in MySQL

AmitDiwan
Updated on 04-Oct-2019 06:32:27

993 Views

For this, you can use subquery. Let us first create a table −mysql> create table DemoTable (    StudentName varchar(40),    StudentMarks int ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam', 56); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Chris', 78); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Adam', 89); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Robert', 98); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Chris', 65); Query OK, 1 ... Read More

Area of Squares Formed by Joining Midpoints Repeatedly in C

sudhir sharma
Updated on 03-Oct-2019 13:24:05

128 Views

Area of a square is equal to the product of sides of the square.We are considering a figure in which the midpoints of sides of each square make another square. And so on until a specific number of squares.This figure shows a square made by joining the midpoints of a square.For this figure the let the side be a, The length of side of inner square will beL2 = (a/2)2 + (a/2)2 L2 = a2(1/4 + 1/4) = a2(1/2) = a2/2 L = a2/ (\sqrt{2}).Area of square2 = L2 = a2/2.For the next square, the area of square 3 = ... Read More

Area of the Biggest Possible Rhombus Inscribed in a Rectangle in C

sudhir sharma
Updated on 03-Oct-2019 13:13:52

267 Views

A rhombus inscribed in a rectangle touches the sides of the rectangle so by this we can infer that the diagonals of the largest inscribed rhombus are equal to the length and breadth of the rectangle.If we have the length(l) and breadth(b) of the rectangle, the length of the diagonal of the largest rhombus inscribed inside it is d1 = l and d2 = b.The area of a rhombus is given by the formula, Area = (d1*d2)/2Putting the values of d1 and d2. We get, Area = (l*b)/2Using this formula we can create a program that calculates the area of ... Read More

Area of a Circle Inscribed in a Rectangle within a Semicircle in C

sudhir sharma
Updated on 03-Oct-2019 13:10:41

2K+ Views

A circle inscribed in a rectangle touches the larger side of the rectangle with its ends i.e. the length is tangent to the circle.A rectangle inscribed in a semicircle touches its arc at two points. The breadth of the rectangle is equal to the diameter of the circle.If R is the radius of semi-circle.Length of the rectangle = √2R/2Breadth of the rectangle = R/√2Radius of biggest circle inscribed isr = b/2 = R/2√2Using this formula we can find the area of this circle inscribed in a rectangle which is inscribed in a semicircle, Area = (π*r2) = π*R/8Example Live Demo#include ... Read More

Anti-Clockwise Spiral Traversal of a Binary Tree in C++

sudhir sharma
Updated on 03-Oct-2019 13:02:36

175 Views

Anti-Clockwise spiral traversal of a binary tree is traversing the elements of a tree in such a way that if traversed they make a spiral but in reverse order. The following figure shows how a anti-clockwise spiral traversal of binary tree.The Algorithm defined for spiral traversal of a binary tree works in the following way −Two variables i and j are initialized and values are equated as i = 0 and j = height of variable. A flag is used to check while section is to be printed. Flag is initially is set of false. A loop working till i ... Read More

Arc Length from Given Angle in C++

sudhir sharma
Updated on 03-Oct-2019 12:58:30

465 Views

An Angle is formed when two rays meet at a point. The point on the plane at which these rays meet is vertex.Arc of a circle is a portion of the circumference that is described by an angle.In this problem, we are given an angle of the circle. And we need to find the length of arc using the given diameter of the circle. For example, Input : Angle = 45° Diameter = 28 Output : Arc = 11ExplanationLength of arc = (circumference) X (angle/360°)= (π * d)*(angle/360°)To make a program that calculates the length of Arc from the given ... Read More

A Product Array Puzzle in C

sudhir sharma
Updated on 03-Oct-2019 12:51:23

345 Views

An array is a container of elements of the same data types. In product array Puzzle, the product of all elements is found.In this Product Array Puzzle, we need to find the product of all elements of the array except element. The condition is that you cannot use the division operator and store this to another array.For solving this we will be creating two products, one for all left elements and one for all right elements. And then adding this left and right products to get the desired products.Example Live Demo#include #include void productfind(int arr[], int n) {    int *left ... Read More

Advertisements