Display Timestamp before the current date in MySQL

AmitDiwan
Updated on 27-Sep-2019 07:29:31

98 Views

Let us first create a table −mysql> create table DemoTable(    ArrivalDate timestamp ); Query OK, 0 rows affected (1.96 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-09-14 17:25:00'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('2019-09-13 17:25:00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2016-09-01 17:20:10'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable values('2019-09-11 12:00:00'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+---------------------+ | ... Read More

MySQL query to concatenate all the values in each row based on the common matching ID

AmitDiwan
Updated on 27-Sep-2019 07:25:36

90 Views

Let us first create a table −mysql> create table DemoTable (    StudentId int,    StudentFirstName varchar(100),    StudentLastName varchar(100) ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1000, 'Adam', 'Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(1000, 'John', 'Doe'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(1000, 'David', 'Miller'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-----------+------------------+-----------------+ | StudentId | StudentFirstName ... Read More

MySQL query to sum the Product Price values from similar columns for same customers and display the result in the same column

AmitDiwan
Updated on 27-Sep-2019 07:22:26

338 Views

For this, use SUM() along with GROUP BY. Let us first create a table −mysql> create table DemoTable (    CustomerName varchar(100),    Product_1_Price int,    Product_2_Price int ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 67, 89); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('David', 769, 890); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('David', 987, 1000); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('John', 900, 111); Query OK, 1 row affected (0.12 sec)Display ... Read More

Display records by first fixing the first two values in a column and then using DISTINCT to display other values in MySQL

AmitDiwan
Updated on 27-Sep-2019 07:19:12

52 Views

Let us first create a table −mysql> create table DemoTable (    FirstName varchar(100) ); Query OK, 0 rows affected (0.96 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-----------+ | FirstName | ... Read More

How can I count unique records from a column in MySQL database?

AmitDiwan
Updated on 27-Sep-2019 07:17:32

97 Views

For this, use aggregate function count(*) to count to GROUP BY to group. Let us first create a table −mysql> create table DemoTable (    UserName varchar(100),    UserPostMessage text ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'Hi'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('David', 'Hello'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Chris', 'Awesome'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Chris', 'Amazing'); Query OK, 1 row affected (0.17 sec) mysql> insert ... Read More

MySQL query to display records ordered by DESC while skipping some?

AmitDiwan
Updated on 27-Sep-2019 07:14:25

57 Views

Let us first create a table −mysql> create table DemoTable (    Id int,    Name varchar(100) ); Query OK, 0 rows affected (0.94 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 'Chris'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(1, 'David'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(4, 'Bob'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(6, 'Sam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(7, 'Mike'); Query OK, 1 row affected (0.10 sec) mysql> insert ... Read More

Find the next lowest number higher than a certain number in MySQL?

AmitDiwan
Updated on 27-Sep-2019 07:11:28

200 Views

For this, use aggregate function MIN() along with WHERE clause. Let us first create a table −mysql> create table DemoTable (    Number int ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(11); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(9); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(12); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This ... Read More

How do you properly ignore Exceptions in Python?

Rajendra Dharmkar
Updated on 27-Sep-2019 07:10:07

444 Views

This can be done by following codestry: x, y =7, 0 z = x/y except: passORtry: x, y =7, 0 z = x/y except Exception: passThese codes bypass the exception in the try statement and ignore the except clause and don’t raise any exception.The difference in the above codes is that the first one will also catch KeyboardInterrupt, SystemExit etc, which are derived directly from exceptions.BaseException, not exceptions.Exception.It is known that the last thrown exception is remembered in Python, some of the objects involved in the exception-throwing statement are kept live until the next exception. We might want to do ... Read More

MySQL query to change a string by displaying only the part of string after underscore?

AmitDiwan
Updated on 27-Sep-2019 07:04:32

63 Views

Let us first create a table −mysql> create table DemoTable (    UserName varchar(100) ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Smith_John'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Smith_Adam'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Smith_David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Smith_Mike'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-------------+ | UserName ... Read More

What are RuntimeErrors in Python?

Manogna
Updated on 27-Sep-2019 07:03:31

488 Views

A syntax error happens when Python can't understand what you are saying. A run-time error happens when Python understands what you are saying, but runs into trouble when following your instructions. This is called a run-time error because it occurs after the program starts running.A program or code may be syntactically correct and may not throw any syntax error. This code may still show error after it starts running.The given code can be corrected as followsa = input('Enter a number:') b = input('Enter a number:') c = a*b print cThe output we get is as follows"C:/Users/TutorialsPoint1/~.py" Enter a number:7 Enter ... Read More

Advertisements