MySQL Query to Fetch Records Where Decimal is a Whole Number

AmitDiwan
Updated on 07-Oct-2019 11:24:49

458 Views

For this, use FLOOR() function. Here, we will be fetching records like 12.00, 35.00, etc. from a list with records like 5.23, 8.76, 12.00, 22.68, etc. Let us first create a table −mysql> create table DemoTable (    Value DECIMAL(4, 2) ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(54.20); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(55.0); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(7.8); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(9.0); Query OK, ... Read More

Find Percentage of a Student Based on Marks in SQL

AmitDiwan
Updated on 07-Oct-2019 11:23:05

2K+ Views

Let us first create a table −mysql> create table DemoTable (    Marks int ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(88); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(65); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(98); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(45); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(67); Query OK, 1 row affected (0.33 sec)Display all records from the table using select statement −mysql> select ... Read More

Delete Row in MySQL If Two Columns Are Equal

AmitDiwan
Updated on 07-Oct-2019 11:20:38

488 Views

Use DELETE for this. Let us first create a table −mysql> create table DemoTable (    Name varchar(40),    Score1 int ,    Score2 int ); Query OK, 0 rows affected (2.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 56, 76); Query OK, 1 row affected (0.66 sec) mysql> insert into DemoTable values('Chris', 77, 77); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('David', 89, 98); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output ... Read More

Get Difference Between Date Records and Current Date in MySQL

AmitDiwan
Updated on 07-Oct-2019 11:16:46

213 Views

Let’s say the current date is 2019-09-06. For our example, we will first create a table −mysql> create table DemoTable (    AdmissionDate date ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-08'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('2018-09-06'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2016-10-26'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+---------------+ | AdmissionDate | +---------------+ | 2019-01-08 ... Read More

Update a Column of Text with MySQL REPLACE

AmitDiwan
Updated on 07-Oct-2019 10:52:50

901 Views

Let us first create a table −mysql> create table DemoTable (    Code varchar(100) ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('8565-9848-7474'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('9994-6464-8737'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('6574-9090-7643'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----------------+ | Code          | +----------------+ | 8565-9848-7474 | | 9994-6464-8737 | | ... Read More

Convert MySQL DATETIME Value to JSON Format in JavaScript

AmitDiwan
Updated on 07-Oct-2019 10:49:22

656 Views

To convert, use JSON.stringify(). Following is the code to convert MySQL DATETIME value to JSON format in JavaScript − var mySQLDateTime = new Date("Fri Sep 06 2019 22 −54 −48 "); var yearValue = mySQLDateTime.getFullYear(); var dateValue = mySQLDateTime.getDate(); var monthValue=mySQLDateTime.getMonth(); var hour=mySQLDateTime.getHours(); var minutes=mySQLDateTime.getMinutes(); var second=mySQLDateTime.getSeconds(); jsonObject={"year" −yearValue,"month" :monthValue,"DateValue" :dateValue,"Hour" :hour ,"Minutes" :minutes,"Second" :second}; var dateJsonObject = JSON.stringify(jsonObject); document.write(dateJsonObject); The screenshot of the code is as follows −This will produce the following output −{"year" :2019,"month" :8,"DateValue" :6,"Hour" :22,"Minutes" :54,"Second" :48}The snapshot of the output is as follows −

MySQL Select Query to Return Records with Specific Month and Year

AmitDiwan
Updated on 07-Oct-2019 10:45:23

1K+ Views

For specific month, use MONTH() and for year, use YEAR() method. Let us first create a table −mysql> create table DemoTable (    StudentName varchar(40),    StudentAdmissionDate date ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', '2019-01-21'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Robert', '2018-09-05'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Mike', '2019-09-05'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('David', '2019-10-04'); Query OK, 1 row affected (0.14 sec)Display all records from the ... Read More

MySQL Query to Return a String as a Result of IF Statement

AmitDiwan
Updated on 07-Oct-2019 10:42:43

499 Views

Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    EmployeeSalary int ); Query OK, 0 rows affected (1.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(EmployeeSalary) values(12000); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(EmployeeSalary) values(20000); Query OK, 1 row affected (0.55 sec) mysql> insert into DemoTable(EmployeeSalary) values(11500); Query OK, 1 row affected (0.94 sec) mysql> insert into DemoTable(EmployeeSalary) values(15500); Query OK, 1 row affected (0.44 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce ... Read More

Update Column Values with Date Records in SQL

AmitDiwan
Updated on 07-Oct-2019 10:40:03

293 Views

Let’s say the current date is 2019-08-20. Now for our example, we will create a table −mysql> create table DemoTable (    ProductStatus tinyint(1),    ProductExpiryDate date ); Query OK, 0 rows affected (1.03 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(0, '2019-06-12'); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable values(0, '2019-10-11'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable values(0, '2018-07-24'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(0, '2018-09-05'); Query OK, 1 row affected (0.27 sec)Display all records from the table ... Read More

C++ Pointer Puzzle

sudhir sharma
Updated on 07-Oct-2019 08:19:16

436 Views

A Pointer is a variable that stores the address of another variable. The data type of the pointer is the same as the data type as the variable.In this puzzle you need to know the size of the pointer that is being used. The puzzle checks our understanding of pointers by asking you the size of variable.The size of int is 4 bytes, whereas the size of int pointer is 8. Now, let’s test your skills with the following exercise in c++ programming language.Example Live Demo#include using namespace std; int main() {    int a = 6 ;    int ... Read More

Advertisements