AmitDiwan has Published 11365 Articles

Search records on the basis of date in MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:45:58

110 Views

Let us first create a table -mysql> create table DemoTable732 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, PassengerId int, PassengerName varchar(100), PassengerAge int, PassengerTravelDatetime datetime ); Query OK, 0 rows affected (0.67 sec)Insert some ... Read More

Convert string (varchar) to double in MySQL

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:43:51

2K+ Views

Let us first create a table:mysql> create table DemoTable731 (Value varchar(100)); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command -mysql> insert into DemoTable731 values('4.50'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable731 values('7.83'); Query OK, 1 row affected (0.18 sec) ... Read More

Assign an SQL result to variable from prepared statement in MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:42:59

1K+ Views

For this, use stored procedure. Let us first create a table −mysql> create table DemoTable(Id int, Name varchar(100)); Query OK, 0 rows affected (1.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 'John'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable ... Read More

MySQL query to count days in date range with start and end date

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:41:11

696 Views

To count days in date range, you need to find the difference between dates using DATEDIFF().Let us first create a table:mysql> create table DemoTable730 (    StartDate date,    EndDate date ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert command:mysql> insert into DemoTable730 ... Read More

Display the student marks in a single column on the basis of subject in MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:40:10

2K+ Views

For this, use UNION ALL.Let us first create a table:mysql> create table DemoTable729 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(100),    MySQLMarks int,    CMarks int,    JavaMarks int ); Query OK, 0 rows affected (0.40 sec)Insert some records in the table using insert command:mysql> ... Read More

Calculating power of a number in MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:39:06

83 Views

To calculate power of a number, use POWER() function. Let us first create a table −mysql> create table DemoTable    (       Amount int    ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(64); Query OK, ... Read More

Convert UK DATE to MySQL date?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:36:41

259 Views

The UK date format supports day-moth-year format. To convert it to MySQL date, use STR_TO_DATE(). Following is the syntax:select str_to_date(yourColumnName, '%d/%m/%Y') from yourTableName;Let us first create a table:mysql> create table DemoTable728 (DueDate varchar(100)); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command:mysql> insert into ... Read More

Selecting a value in custom order from another column in a MySQL table with a single query

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:35:16

93 Views

For this, you can use IN().Let us first create a table:mysql> create table DemoTable727 (    Name varchar(100),    Score int ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command:mysql> insert into DemoTable727 values('Chris', 45); Query OK, 1 row affected (0.18 sec) mysql> ... Read More

Replace date format with MySQL STR_TO_DATE

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:33:37

306 Views

Let us first create a table −mysql> create table DemoTable(DueDate varchar(100)); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('10-01-2019 10:19:20'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('12-03-2018 11:00:00'); Query OK, 1 row affected ... Read More

How to sort varchar numeric columns by DESC or ASC in MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:33:35

395 Views

Let us first create a table −mysql> create table DemoTable726 (Value varchar(100)); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable726 values('100'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable726 values('10'); Query OK, 1 row affected (0.15 ... Read More

Advertisements