Performing Mathematics : Select « Select Clause « SQL / MySQL






Performing Mathematics

  
/* Prepare the data */  
DROP TABLE  Exam;
CREATE TABLE Exam (
   StudentID  INT NOT NULL,
   ExamID     INT NOT NULL,
   Mark       INT,
   IfPassed   SMALLINT
)TYPE = InnoDB;

/* Insert data for testing */
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassed) VALUES (1,1,55,1);
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassed) VALUES (1,2,73,0);
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassed) VALUES (2,3,44,1);

/* Real command */
SELECT StudentID, ExamID, Mark * IfPassed AS MarkIfPassed FROM Exam;

           
         
    
  








Related examples in the same category

1.Define and use variable in select clause
2.Use defined variable in new select clause
3.Select clause with condition
4.Choose specific columns
5.Reference column in select command
6.Simple Retrieval:Returning Multiple Columns
7.Simple Retrieval:Returning a Single Column
8.Simple Retrieval: Returning All Columns
9.Performing a Single Row INSERT
10.Retrieve all columns in a table
11.Using constant string value as comment message for aggregate function
12.Calculation