How to sum the values in the table by month with MySQL?

AmitDiwan
Updated on 12-Nov-2019 05:19:52

2K+ Views

For this, use EXTRACT(), that would allow you to extract specific month records. For example, to add all the prices in January (irrespective of the year).Let us first create a −mysql> create table DemoTable1415    -> (    -> ProductPurchaseDate date,    -> ProductPrice int    -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert −mysql> insert into DemoTable1415 values('2019-01-12', 560); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1415 values('2018-01-14', 1060); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1415 values('2017-03-21', 780); Query OK, 1 row affected (0.11 ... Read More

Select multiple Book Titles that share the minimum (PRICE) value in MySQL?

AmitDiwan
Updated on 12-Nov-2019 05:17:49

148 Views

For this, use MySQL MIN(). Let us first create a −mysql> create table DemoTable1414    -> (    -> BookTitle varchar(40),    -> BookPrice int    -> ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert −mysql> insert into DemoTable1414 values('Deep dive using java', 560); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1414 values('C++ in depth', 360); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1414 values('Data structure in C', 590); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1414 values('Algorithm in C++', 1090); Query OK, 1 ... Read More

Fastest way to search for a date from the date records in MySQL

AmitDiwan
Updated on 12-Nov-2019 05:15:05

208 Views

The fastest and easiest way is to use the MySQL BETWEEN keyword. Let us first create a −mysql> create table DemoTable1413    -> (    -> EmployeeName varchar(20),    -> EmployeeJoiningDate datetime    -> ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert −mysql> insert into DemoTable1413 values('Chris', '2018-09-28 11 :10 :50'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1413 values('David', '2019-09-28 11:10:50'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1413 values('Mike', '2019-09-29 12:40:00'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1413 values('Carol', '2019-09-28 12:06:10'); ... Read More

MySQL query to check if a certain row has only two words?

AmitDiwan
Updated on 12-Nov-2019 05:13:35

254 Views

For this, use Regular Expression in MySQL as in the below syntax −select * from yourTableName where yourColumnName regexp '^[^ ]+[ ]+[^ ]+$';The above query will work when the two words are separated by a space. Let us first create a −mysql> create table DemoTable1412    -> (    -> Name varchar(40)    -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert −mysql> insert into DemoTable1412 values('John Adam Carol'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1412 values('Mike Sam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1412 ... Read More

MySQL query to find a value in a set of values separated by comma in a custom variable

AmitDiwan
Updated on 12-Nov-2019 05:12:02

168 Views

For this, use FIND_IN_SET() in MySQL and use the value from a custom variable. Let us first create a −mysql> create table DemoTable1411    -> (    -> Value int    -> )    -> ; Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert −mysql> insert into DemoTable1411 values(10); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1411 values(50); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1411 values(60); Query OK, 1 row affected (0.08 sec)Display all records from the table using select −mysql> select * from DemoTable1411;This will produce ... Read More

How to mask data fields in MySQL?

AmitDiwan
Updated on 12-Nov-2019 05:08:56

1K+ Views

To mask data fields, use CONCAT() along with REPEAT(). Here, we will mask data fields with #. Let us first create a −mysql> create table DemoTable1410    -> (    -> Password varchar(80)    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert −mysql> insert into DemoTable1410 values('John12345678'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1410 values('Carol_897'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1410 values('David_5647383'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select −mysql> select * from DemoTable1410;This will produce ... Read More

jQuery event.namespace Property

AmitDiwan
Updated on 11-Nov-2019 13:09:02

110 Views

The event.namespace property in jQuery is used to return the custom namespace when the event was triggered.SyntaxThe syntax is as follows −event.namespaceExampleLet us now see an example to implement the jQuery event.namespace property −    $(document).ready(function(){       $("p").on("custom.demoNamespace", function(event){          alert(event.namespace);       });       $("p").click(function(event){          $(this).trigger("custom.demoNamespace");       });       $("button").click(function(){          $("p").off("custom.demoNamespace");       });    }); Demo Heading This is demo paragraph. This is demo paragraph. Remove namespace Click on any ... Read More

jQuery event.delegateTarget Property

AmitDiwan
Updated on 11-Nov-2019 13:04:43

89 Views

The event.delegateTarget property in jQuery is used to return the element where the currently-called jQuery event handler was attached.SyntaxThe syntax is as follows −event.delegateTargetExampleLet us now see an example to implement the jQuery event.delegateTarget property −    $(document).ready(function(){       $("div").on("click", "button", function(event){          $(event.delegateTarget).css("color", "red");       });    }); Demo Heading Change color by clicking on below button. This is demo text. Click to change color OutputThis will produce the following output −Above, click on the button to change the text color −

jQuery event.data Property

AmitDiwan
Updated on 11-Nov-2019 13:01:32

173 Views

The event.data property in jQuery contains the optional data passed to an event method when the current executing handler is bound.SyntaxThe syntax is as follows −event.dataExampleLet us now see an example to implement the jQuery event.data property −    $(document).ready(function(){       $("p").each(function(i){          $(this).on("click", {a:i}, function(event){             alert("Line " + event.data.a);          });       });    }); Demo Heading This is the 1st paragraph. This is the 2nd paragraph. Click on any of the p element above OutputThis will produce the following output −Click on any of the p element −

jQuery event.currentTarget Property

AmitDiwan
Updated on 11-Nov-2019 12:57:50

162 Views

The event.currentTarget property in jQuery is the current DOM element within the event bubbling phase.SyntaxThe syntax is as follows −event.currentTargetExampleLet us now see an example to implement the jQuery event.currentTarget property −    $(document).ready(function(){       $("h1, p").click(function(event){          alert(event.currentTarget === this);       });    }); World Countries list... Click on any of the above element and witness a magic. OutputThis will produce the following output −Click on any of the element above and an alert box generates −

Advertisements