Select Average from Distinct Column in MySQL

AmitDiwan
Updated on 30-Dec-2019 07:46:21

548 Views

For getting average, use AVG() and use it with DISTINCT to calculate from distinct records. Let us first create a table −mysql> create table DemoTable1934    (    StudentName varchar(20),    StudentMarks int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1934 values('Chris', 56); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1934 values('Chris', 56); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1934 values('David', 78); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1934 values('David', 78); Query OK, 1 row affected ... Read More

jQuery :has() Selector with Examples

AmitDiwan
Updated on 30-Dec-2019 07:45:27

332 Views

The has() method in jQuery is used to return elements having one or more elements inside them, that matches the specified selector.SyntaxThe syntax is as follows−$(selector).has(ele)Above, the parameter ele is used to specify a selector expression or an element to match elements against.ExampleLet us now see an example to implement the jQuery has() method − Live Demo    $(document).ready(function(){       $("button").click(function(){          $("p").has("span").css("color", "orange");       });    }); h2 {    color: blue; } Student Info This is a demo text. Exam Info This is ... Read More

Display Table Records from a Stored Procedure in MySQL

AmitDiwan
Updated on 30-Dec-2019 07:43:55

1K+ Views

Let us first create a table −mysql> create table DemoTable1933    (    ClientName varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1933 values('Chris Brown'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1933 values('David Miller'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1933 values('Adam Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1933 values('John Doe'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1933;This will produce the ... Read More

Select Items Based on Value and Order by Date in MySQL

AmitDiwan
Updated on 30-Dec-2019 07:42:25

372 Views

Use ORDER BY to fix a record and then displayselect * from yourTableName order by yourColumnName1=yourValue desc, yourColumnName2;Let us first create a table −mysql> create table DemoTable1932    (    UserName varchar(20),    ShippingDate date    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1932 values('Chris', '2018-10-12'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1932 values('David', '2019-04-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1932 values('Mike', '2016-12-04'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1932 values('Carol', '2017-12-26'); Query OK, 1 ... Read More

intlchar_isxdigit Function in PHP

karthikeya Boyini
Updated on 30-Dec-2019 07:41:30

131 Views

The IntlChar::isxdigit() function checks whether the given input character is a hexadecimal digit or not. The following are the hexadecimal digits −Digit numbers (0 – 9)Letters (a – f) and (A – F)\u{0041} to \u{0046}, \u{0061} to \u{0066}, \u{FF21} to \u{FF26}\u{FF41} to \u{FF46}).SyntaxIntlChar::isxdigit( val )Parametersval − An integer values or character encoded as a UTF-8 string.ReturnThe IntlChar::isxdigit() function returns TRUE if the val is a hexadecimal digit.ExampleThe following is an example −var_dump(IntlChar::isxdigit("10")); echo ""; // Input data is character type var_dump(IntlChar::isxdigit("A")); echo ""; var_dump(IntlChar::isxdigit("a")); echo "";OutputThe following is the output −bool(true) NULL bool(true)ExampleLet us see another example −OutputThe following is ... Read More

Extract Month and Year in MM-YYYY Format from MySQL

AmitDiwan
Updated on 30-Dec-2019 07:41:08

737 Views

For month and year in a specific format, use DATE_FORMAT() along with STR_TO_DATE(). Let us first create a table −mysql> create table DemoTable1931    (    ShippingDate varchar(40)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1931 values('10-11-2017'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1931 values('31-01-2019'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1931 values('02-02-2018'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1931 values('10-06-2013'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select ... Read More

intlchar_iscntrl Function in PHP

Samual Sam
Updated on 30-Dec-2019 07:39:32

134 Views

The IntlChar::iscntrl() function is used to check the given input is a control character or not. Examples include line feed (), tab (\t), etc.SyntaxIntlChar::iscntrl( val )Parametersval − An integer values or character encoded as a UTF-8 string.ReturnThe IntlChar::iscntrl() function returns TRUE if the val is a control character.ExampleThe following is an example −OutputThe following is the output −bool(true) NULL NULLExampleLet us now see another example wherein we are checking whether the entered value is a control character or not −OutputThe following is the output −bool(true) NULL

Add Days with Interval of 45 Days in MySQL Query

AmitDiwan
Updated on 30-Dec-2019 07:38:36

576 Views

For this, you can use date_add(). Let us first create a table −mysql> create table DemoTable1930    (    DueTime datetime    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1930 values('2017-10-21'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1930 values('2019-12-14'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1930 values('2018-11-26'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1930 values('2014-06-16'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1930;This will ... Read More

IntlChar isPrint Function in PHP

karthikeya Boyini
Updated on 30-Dec-2019 07:37:57

162 Views

The IntlChar::isprint() function checks whether the given input character is a printable character or not.SyntaxIntlChar::isprint( val )Parametersval − An integer values or character encoded as a UTF-8 string. Required!ReturnThe IntlChar::isprint() function returns TRUE if the val is a printable characterExampleThe following is an example −OutputThe following is the output −bool(true) bool(true) bool(false)ExampleLet us see another example −OutputThe following is the output −NULL bool(true) NULL

Reset Primary Key in MySQL

AmitDiwan
Updated on 30-Dec-2019 07:37:17

644 Views

To reset primary key, at first use TRUNCATE table, then use ALTER TABLE. Let us first create a table −mysql> create table DemoTable1929    (    UserId int NOT NULL AUTO_INCREMENT,    PRIMARY KEY(UserId)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1929 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1929 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1929 values(); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1929;This ... Read More

Advertisements