Select multiple sums with MySQL query and display them in separate columns?

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

772 Views

To select multiple sum columns with MySQL query and display them in separate columns, you need to use CASE statement. The syntax is as follows:SELECT SUM( CASE WHEN yourColumnName1=’yourValue1’ THEN yourColumnName2 END ) AS yourSeparateColumnName1, SUM( CASE WHEN yourColumnName1=’yourValue2’ THEN yourColumnName2 END ) AS yourSeparateColumnName2, SUM( CASE WHEN yourColumnName1=’yourValue3’ THEN yourColumnName2 END ) AS yourSeparateColumnName3, . . . N FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table selectMultipleSumDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> PlayerName varchar(20),    -> PlayerScore int, ... Read More

Formatting a Negative Number Output with Parentheses in Java

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

408 Views

A negative number output can be shown using the Formatter object −Formatter f = new Formatter(); f.format("%12.2f", -7.598); System.out.println(f);Try the below given code to format a Negative Number Output with Parentheses −Formatter f = new Formatter(); f.format("%(d", -50); System.out.println(f);The following is an example −Example Live Demoimport java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); f.format("% d", 50); System.out.println(f); // negative number inside parentheses f = new Formatter(); f.format("%(d", -50); System.out.println(f); } }Output50 (50)

How to select record from last 6 months in a news table using MySQL?

George John
Updated on 30-Jul-2019 22:30:24

4K+ Views

To select the last 6 months records from news table, use the date_sub() function from MySQL since news records are arranged according to date.The syntax is as follows −select *from yourTableName where yourDateTimeColumnName >= date_sub(now(), interval 6 month);To understand the above concept, let us first create a NEWS table with only NEWS ID and the date on which it published −mysql> create table Newstable -> ( -> NewsId int, -> NewsDatetime datetime -> ); Query OK, 0 rows affected (0.66 sec)Insert records in the table using insert command. ... Read More

Can MySQL automatically store timestamp in a row?

Chandu yadav
Updated on 30-Jul-2019 22:30:24

2K+ Views

Yes, you can achieve this in the following two ways.First Approach At the time of creation of a table.Second Approach At the time of writing query.The syntax is as follows.CREATE TABLE yourTableName ( yourDateTimeColumnName datetime default current_timestamp );You can use alter command.The syntax is as follows.ALTER TABLE yourTableName ADD yourColumnName datetime DEFAULT CURRENT_TIMESTAMP;Implement both the syntaxes now.The first approach is as follows.mysql> create table CurrentTimeStampDemo -> ( -> CreationDate datetime default current_timestamp -> ); Query OK, 0 rows affected (0.61 sec)If you do not pass any parameter for the column ‘CreationDate’, MySQL by default stores the current timestamp.Insert record in ... Read More

How to load and display an image on iOS App using Swift?

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

818 Views

To load and display an image in iOS app we’ll first need to get an image.Then we’ll drag that image to our project and select copy if required option and our application target.Let’s see the rest with help of an example.Now, we’ll create an UIImageView and assign the image to its image property, for that we’ll create a function.func addImage(imageName img: String) {    let imageView = UIImageView()    imageView.frame = self.view.frame    imageView.contentMode = .scaleAspectFit    if let newImage = UIImage(named: img) {       imageView.image = newImage    }    self.view.addSubview(imageView) }Now, we’ll call this code in ... Read More

What to do to ease up my toddler's molar time?

Ridhi Arora
Updated on 30-Jul-2019 22:30:24

48 Views

Teething makes the child more irritable than usual. The child feels a lot of pain and it is; therefore, necessary to provide them comfort during this time.How To Tackle Babies During their Teething Time of Molars?Diet Change: A diet that consists of soup and yogurt is better than solid foods.An Antidote for Pain: Thick end of a chilled, uncut carrot, for instance, can be a good antidote for molar eruption pain.Icy water to help numb the area, so no pain is felt by the toddler.If the toddler is constantly drooling, keep a towel or soft cloth handy to pat his ... Read More

What is plastic pollution and its effect on the environment?

Tejas Charukula
Updated on 30-Jul-2019 22:30:24

219 Views

Plastic pollution is the most hazardous and most impactful pollution on earth. Unnecessary piling up of the plastic waste in the Earth's environment is adversely affecting the wildlife, wildlife habitat, and humans. Plastic pollution has its effects on land, water, and air along with plants and animals.The implication for animalsMany times we litter the earth with plastic without knowing the dangers that it can cause to other animals and creatures that also co-exist with us on the same planet. Many animals mistake the plastic that we throw away as food and they eat it. In many cases, it has been ... Read More

ORDER BY alphabet first then follow by number in MySQL?

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

713 Views

You need to use regular expression with ORDER BY clause. The syntax is as follows:SELECT *FROM yourTableName ORDER BY IF(yourColumnName RLIKE '^[a-z]', 1, 2), yourColumnName;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table AlphabetFirstThenNumberDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(20),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.95 sec)Insert some records in the table using insert command. The query is as follows:mysql> insert into AlphabetFirstThenNumberDemo(Name) values('John'); Query OK, 1 row affected (0.37 sec) mysql> insert ... Read More

Sample questions for ITIL Foundation Course

yashwanth sitamraju
Updated on 30-Jul-2019 22:30:24

154 Views

Information Technology Infrastructure Library (ITIL) is the framework that is designed to standardize the planning, selection, and delivery of IT services to a business. The goal of ITIL is to improve efficiency and also achieve predictable goals or targets. An ITIL enables an IT professional to be a business service partner, not just back-end support.ITIL Foundation ExaminationIt is a closed book examination.It consists of 40 questions.Each question has multiple choices.One mark is allotted for the correct answer.The duration of the exam is one hour.One has to score 65% of the marks to pass the examination i.e minimum 26 questions must ... Read More

How to create JSON format with group-concat in MySQL?

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

1K+ Views

You can create JSON format using group_concat() function from MySQL. The syntax is as follows −SELECT yourColumnName1, GROUP_CONCAT(CONCAT('{anytName:"', yourColumnName, '", anyName:"', yourColunName, '"}')) anyVariableName from yourTableName group by yourColumnName1;To understand the above syntax, let us first create a table. The query to create a table is as follows −mysql> create table JsonFormatDemo -> ( -> UserId int, -> UserName varchar(100), -> UserEmail varchar(100) -> ); Query OK, 0 rows affected (0.99 sec)Insert some records in the table using insert ... Read More

Advertisements