mysql parentheses in sql command example
mysql-parentheses-in-sql-command-example.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>mysql parentheses in sql command example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Md Iqbal Hosan">
<meta name="title" content="mysql parentheses in sql command example">
<meta name="keywords" content="php, example, code, table, sql command, sql, mysql parentheses">
<meta name="description" content="mysql parentheses in sql command example">
<style>
h2, h4{background:#ccc; color:#000098;}
h2{ padding:3px; margin:3px; font-size:22px;}
h4{ padding:2px; margin:2px; font-size:19px;}
p{padding:2px; margin:2px; color:#0099FF;}
body{ background:#FFFFFC;}
</style>
</head>
<body>
<h2>mysql parentheses in sql command example</h2>
<pre>
<?php
/*
------------------------------------------------------------------------------------
WE WANT TO SELECT LastName, MonthlySalary and annual salary + a bonus of 700 of all
employees of the HR database by using sql command where (annual salary + a bonus of 700)
as AnnualSalary using parentheses
------------------------------------------------------------------------------------
*/
$sql = " SELECT LastName, MonthlySalary, (12*MonthlySalary + 700) AS AnnualSalary FROM employees ";
/*
---------------------------------------------------------------------------------------------
by using AS keyword we can define an alias to rename the column name or column name heading
alias is case sensitive
by using parentheses we can define operator precedence. for example -
if we want to add a commission of 700 for each month then what will be AnnualSalary?
we can use following sql statement to find that :
---------------------------------------------------------------------------------------------
*/
$sql = " SELECT LastName, MonthlySalary, 12*(MonthlySalary + 700) AS AnnualSalary FROM employees ";
?>
</pre>
</body>
</html>


No comments:
Post a Comment
leave your comments here..