Perform MySQL SELECT on dates inserted into the table as VARCHAR values

AmitDiwan
Updated on 26-Sep-2019 07:48:46

46 Views

Let us first create a table −mysql> create table DemoTable (    DueDate varchar(100) ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('21/10/2018'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('18/08/2019'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('01/12/2012'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('31/01/2016'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+------------+ | DueDate ... Read More

Copy column values from one table into another matching IDs in MySQL

AmitDiwan
Updated on 26-Sep-2019 07:46:51

828 Views

Let us first create a table −mysql> create table DemoTable1 (    PersonId int,    Value int ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(100, 78); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable1 values(101, 67); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1 values(102, 89); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output −+----------+-------+ | PersonId | Value | +----------+-------+ |      100 ... Read More

Finding the vertex, focus and directrix of a parabola in Python Program

Pavitra
Updated on 26-Sep-2019 07:46:33

108 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementThe standard form of a parabola equation is y=ax^2+bx+c. Input the values of a, b and c, our task is to find the coordinates of the vertex, focus and the equation of the directrix.The vertex of a parabola is the coordinate from which it takes the sharpest turn whereas y=a is the straight-line used to generate the curve.A directrix a fixed line used in describing a curve or surface.Now let’s see the implementation −Example Live Demodef findparabola(a, b, c):    print ("Vertex: (" , (-b ... Read More

MySQL CONCAT a specific column value with the corresponding record

AmitDiwan
Updated on 26-Sep-2019 07:43:56

69 Views

Let us first create a table −mysql> create table DemoTable (    FirstName varchar(100),    CountryName varchar(100) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam', 'US'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David', 'AUS'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Chris', 'UK'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('John', 'US'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Carol', 'AUS'); Query OK, 1 row affected (0.14 sec)Display all records ... Read More

Find the perimeter of a cylinder in Python Program

Pavitra
Updated on 26-Sep-2019 07:43:38

268 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementInput diameter and height, find the perimeter of a cylinder.Perimeter is nothing but the side view of a cylinder i.e. a rectangle.Therefore Perimeter= 2 * ( h + d )here d is the diameter of the cylinderh is the height of the cylinderNow let’s see the implementationExample Live Demo# Function to calculate the perimeter of a cylinder def perimeter( diameter, height ) :    return 2 * ( diameter + height ) # main diameter = 5 ; height = 10 ; print ("Perimeter = ... Read More

INSERT INTO table if a table exists in MySQL else implement CREATE TABLE and create the table

AmitDiwan
Updated on 26-Sep-2019 07:41:48

851 Views

Here’s the syntax to check whether the table already exists using the CREATE TABLE IF NOT EXISTS −create table if not exists yourTableName (    yourColumnName1 dataType,    .    .    .    .    N ); insert into yourTableName values(yourValue1, .......N);Let us first create a table −mysql> create table if not exists DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentSubject varchar(100) ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentSubject) values('Java'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(StudentSubject) values('MySQL'); ... Read More

How to find a specific record from a list of values with semicolon in MySQL?

AmitDiwan
Updated on 26-Sep-2019 07:38:20

83 Views

For this, you can use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value varchar(100) ); Query OK, 0 rows affected (2.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values('100;200;300'); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable(Value) values('1;300;400'); Query OK, 1 row affected (0.58 sec) mysql> insert into DemoTable(Value) values('6;7;8;9;10'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable(Value) values('1;2;3;4;5'); Query OK, 1 row affected (9.36 sec) mysql> insert into DemoTable(Value) values('3;8;9;10'); Query OK, 1 ... Read More

MySQL query to order timestamp in descending order but place the timestamp 0000-00-00 00:00:00 first?

AmitDiwan
Updated on 26-Sep-2019 07:36:06

953 Views

Let us first create a table &mnus;mysql> create table DemoTable (    `timestamp` timestamp ); Query OK, 0 rows affected (1.12 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(now()); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('00:00:00'); Query OK, 1 row affected (0.73 sec) mysql> insert into DemoTable values('2018-01-10 12:34:45'); Query OK, 1 row affected (0.80 sec) mysql> insert into DemoTable values('2019-12-31 10:50:45'); Query OK, 1 row affected (0.84 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+---------------------+ | timestamp ... Read More

Python Program for Find sum of Series with the n-th term as n^2 – (n-1)^2

Pavitra
Updated on 26-Sep-2019 07:34:20

232 Views

In this article, we will learn about the solution to the problem statement given below:Problem statementWe are given an integer input n and we need to sum of all n terms where the n-th term in a series as expressed below −Tn = n2 - (n-1)2We have direct formulas for computing the sum which includes the squared muktiolicaion of n which involves more time complexity . To reduce that we usr modular multiplication approach hereNow let's see the implementation −Example Live Demo# Python program to find sum of given # series. mod = 1000000007 def findSum(n):    return ((n % mod) ... Read More

MySQL group_concat to add a separator for empty fields?

AmitDiwan
Updated on 26-Sep-2019 07:33:08

299 Views

For this, you can use replace() along with group_concat(). Here, for empty fields, we are displaying a comma as a separator. Let us first create a table −mysql> create table DemoTable (    Id int,    Number varchar(100) ); Query OK, 0 rows affected (2.03 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, '456'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(11, '345'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values(10, ''); Query OK, 1 row affected (0.63 sec) mysql> insert into DemoTable values(10, '278'); Query ... Read More

Advertisements