加号的用法
SELECT @startdate + 1.25 AS 'Start Date',
@startdate + @adddays AS 'Add Date'
减法的用法
SELECT title,
(
(price * ytd_sales) * CAST( ( (100 - royalty) / 100.0 )
AS MONEY)
) AS IncomeAfterRoyalty
FROM titles
乘法的用法
SELECT title_id, price * 1.15 AS NewPrice
FROM titles
WHERE type = 'mod_cook'
ORDER BY title_id ASC
USE pubs
SELECT DISTINCT title
FROM titles
WHERE price >
(SELECT MIN(price)
FROM titles)
下面是结果集:
title
----------------------------------------------------------
But Is It User Friendly?
Computer Phobic and Non-Phobic Individuals: Behavior Variations
Cooking with Computers: Surreptitious Balance Sheets
Emotional Security: A New Algorithm
Fifty Years in Buckingham Palace Kitchens
Is Anger the Enemy?
Life Without Fear
Onions, Leeks, and Garlic: Cooking Secrets of the Mediterranean
Prolonged Data Deprivation: Four Case Studies
Secrets of Silicon Valley
Silicon Valley Gastronomic Treats
Straight Talk About Computers
Sushi, Anyone?
The Busy Executive's Database Guide
(14 row(s) affected)
因为由未修改的比较运算符引入的子查询必须返回单个值,所以除非知道 GROUP BY 或 HAVING 子句本身会返回单个值,否则不能包括 GROUP BY 或 HAVING 子句。例如,下面的查询查找价格高于类型为"trad_cook"的书籍的最低价格的书。
USE pubs
SELECT DISTINCT title
FROM titles
WHERE price >
(SELECT MIN(price)
FROM titles
GROUP BY type
HAVING type = 'trad_cook')
下面是结果集:
title
------------------------------------------------------------------------
But Is It User Friendly?
Computer Phobic AND Non-Phobic Individuals: Behavior Variations
Onions, Leeks, and Garlic: Cooking Secrets of the Mediterranean
Prolonged Data Deprivation: Four Case Studies
Secrets of Silicon Valley
Silicon Valley Gastronomic Treats
Straight Talk About Computers
Sushi, Anyone?
The Busy Executive's Database Guide