Counting Number of Positive and Negative Votes in MySQL

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

1K+ Views

To count number of positive and negative votes, you can use CASE statement along with aggregate function SUM().Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Vote int ); Query OK, 0 rows affected (1.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Vote) values(-10); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Vote) values(100); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Vote) values(45); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Vote) values(-6); Query OK, 1 row ... Read More

Search an Element of ArrayList in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

9K+ Views

An element in an ArrayList can be searched using the method java.util.ArrayList.indexOf(). This method returns the index of the first occurance of the element that is specified. If the element is not available in the ArrayList, then this method returns -1.A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.List; public class Demo { public static void main(String[] args) { List aList = new ArrayList(); aList.add("A"); aList.add("B"); aList.add("C"); ... Read More

Comparing Dates in MySQL Ignoring Time Portion

Anvi Jain
Updated on 30-Jul-2019 22:30:24

832 Views

To compare dates in MySQL except time portion of a datetime field, you can use DATE() function. The syntax is as follows −select *from yourTableName where date(yourColumName) = yourDate;To understand the above concept, let us create a table. The query to create a table is as follows −mysql> create table ComparingDate    −> (    −> Name varchar(100),    −> Login datetime    −> ); Query OK, 0 rows affected (0.50 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into ComparingDate values('John', '2014-04-06 22:50:45'); Query OK, 1 row affected ... Read More

FTP Chmod Function in PHP

Samual Sam
Updated on 30-Jul-2019 22:30:24

136 Views

The ftp_chmod() function set permissions on a remote file via FTP.Syntaxftp_chmod(con, mode, my_file);Parameterscon − The FTP connectionmode − The new permissions.It consists of four numbers −The first number is always zeroThe second number specifies permissions for the OWNERThe third number specifies permissions for the OWNER's USER GROUPThe fourth number specifies permissions for EVERYBODY ELSEPossible values (to set multiple permissions, add up the following numbers) −1 = execute permissions2 = write permissions4 = read permissionsmy_file − The File nameReturnThe ftp_chmod() function returns new file permissions on success or FALSE on error.ExampleThe following is an example to set file permission by changing ... Read More

Order MySQL Records Randomly and Display Name in Ascending Order

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:24

286 Views

You can use subquery to order randomly and display name in asending order. The rand() is used for random, whereas ORDER BY is used to display name records in ascending order. The syntax is as follows −select *from (    select *from yourTableName order by rand() limit anyIntegerValue; ) anyVariableName order by yourColumnName;To understand the above concept, let us create a table. We have an ID as sell as Name, which we want in Ascending order. The query to create a table is as follows −mysql> create table OrderByRandName    −> (    −> Id int,    −> Name varchar(100) ... Read More

FTP Close Function in PHP

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

114 Views

The ftp_close() function closes an FTP connection.Syntaxftp_close(con);Parameterscon − The connection to close.ReturnThe ftp_close() function returns TRUE on success or FALSE on failureExampleThe following is an example that login to a connection, works in it to change the directory and then connection is closed −

Equivalent of SQL Server Function SCOPE_IDENTITY in MySQL

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

2K+ Views

The equivalent of SQL Server function SCOPE_IDENTITY() is equal to LAST_INSERT_ID() in MySQL. The syntax is as follows:SELECT LAST_INSERT_ID().This returns the id of last inserted record.Here, I am going to create a table with primary key column. The following is the demo of last_insert_id().First, let us create two tables. The query to create the first table table is as follows:mysql> create table TestOnLastInsertIdDemo    -> (    -> StudentId int NOT NULL AUTO_INCREMENT,    -> PRIMARY KEY(StudentId)    -> ); Query OK, 0 rows affected (0.95 sec)Now creating the second table. The query is as follows:mysql> create table TestOnLastInsertIdDemo2   ... Read More

Get Sub Map from TreeMap in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

242 Views

To get Sub Map in Java, use the submap() method. It returns the elements in a range from the Map.First, create a TreeMap and add elements −TreeMap m = new TreeMap(); m.put(1, "PHP"); m.put(2, "jQuery"); m.put(3, "JavaScript"); m.put(4, "Ruby"); m.put(5, "Java"); m.put(6, "AngularJS"); m.put(7, "ExpressJS");Now, get the Sub Map between 4 and 6 −m.subMap(4, 6)The following is an example to get Sub Map from Tree Map in JavaExample Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeMap m = new TreeMap(); m.put(1, ... Read More

Create Date from Day, Month, Year Fields in MySQL

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:24

3K+ Views

You can use in-built function STR_TO_DATE() from MySQL. The syntax is as follows −SELECT STR_TO_DATE(CONCAT(yourYearColumName, '-', LPAD(yourMonthColumName, 2, '00'), '-', LPAD(yourDayColumName, 2, '00')), '%Y-%m-%d') as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table DateCreateDemo    −> (    −> `Day` varchar(2),    −> `Month` varchar(2),    −> `Year` varchar(4)    −> ); Query OK, 0 rows affected (1.68 sec)Insert values for all fields using insert command. The query is as follows −mysql> insert into DateCreateDemo values('15', '12', '2018'); Query OK, 1 row affected (0.09 ... Read More

Teach Quantitative Aptitude for SAT in India: Certification Needed?

Divya Agarwal
Updated on 30-Jul-2019 22:30:24

81 Views

There is no certification nor one required to teach Quantitative aptitude for SAT. The faculty should have the required qualification and experience though.

Advertisements