5
select prod_id,prod_price,prod_name
–from Products
–where vend_id =‘1001’ or prod_price <=10
–//查看执行的数据,当执行 vend_id =‘1001’ or vend_id =‘1005’ and 就不执行了
–select prod_name,prod_price,vend_id
–from Products
–where vend_id =‘1001’ or vend_id =‘1005’
–and prod_price >=10
–in 与 or 相当
–select prod_name,prod_price,vend_id
–from Products
–where vend_id in(‘1001’,‘1005’)
–order by prod_name
– 查找vend_id不是1001的数据
–select prod_name,vend_id
–from Products
–where Not vend_id=‘1001’
–order by prod_name
6章
–百分号通配符 %表示任意字符出现的任意次数,但不会匹配null
–select prod_id,prod_name
–from Products
–where prod_name like ‘F%’
–下划线 _ 通配符 _ 匹配单个字符,不是多个字符
–select prod_name,prod_id
–from Products
–where prod_name like ‘_afe’
–方括号 [] 通配符 用来 指定 一个 字符 集, 它 必须 匹配 指定 位置( 通配符 的 位置) 的 一个 字符。
–select cust_contact
–from Customers
–where cust_contact like ‘[JM]%’
–order by cust_contact
–此 通配符 可以 用 前缀 字符^( 脱 字号) 来 否定。 查询不是JM开头的数据
7章
–拼接字段 也可以使用 || 替代+
– select vend_name + ‘(’ +vend_country + ‘)’
–from Vendors
–order by vend_name
–RTRIM() 函数去掉值右边 的 所有 空格。 LTRIM()函数去掉值左边的所有空格 TRIM去掉左右两边的空格 as为一个新的字段赋新的名字
–select Rtrim(vend_name) + ’ (’ +rtrim(vend_country) +’)’ as vend_title
–from Vendors
–order by vend_name
–执行算数计算
–select prod_id,quantity ,item_price
–from OrderItems
–where order_num=20005
–执行算数计算
–select prod_id,quantity,item_price,quantity*item_price as Ex_price
–from OrderItems
–where order_num=20005
8章
–函数
–UPPER()将字符装换大写
–select vend_name ,UPPER(vend_name) as Ex_name
–from Vendors
–order by vend_name
–字符串操作
–LEFT()返回 字符串 左边 的 字符
–LENGTH()( 也 使用 DATALENGTH() 或 LEN()) 返回 字符串 的 长度
–LOWER()( Access 使用 LCASE())将 字符串 转换 为 小写
–LTRIM() 去掉 字符串 左边 的 空格
–RIGHT()( 或 使用 子 字符串 函数) 返回 字符串 右边 的 字符
–RTRIM() 去掉 字符串 右边 的 空格
–SOUNDEX() 返回 字符串 的 SOUNDEX 值
–UPPER()( Access 使用 UCASE()) 将 字符串 转换 为 大写
–DATEPART() 函数,顾名思义, 此 函数 返回 日期 的 某一 部分。 DATEPART() 函数 有两 个 参数, 它们 分别 是 返回 的 成分 和 从中 返回 成分 的 日期。
–常用 数值 处理 函数
–ABS() 返回 一 个数 的 绝对值
–COS() 返回 一个 角度 的 余弦
–EXP() 返回 一 个数 的 指 数值
–PI() 返回 圆周率
–SIN() 返回 一个 角度 的 正弦
–SQRT() 返回 一 个数 的 平方根
–TAN() 返回 一个 角度 的 正切
9章
–SQL 聚集函数 函数 说 明
–AVG() 返回 某 列 的 平均值
–COUNT() 返回 某 列 的 行数
–MAX() 返回 某 列 的 最大值
–MIN() 返回 某 列 的 最小值
–SUM() 返回 某 列 值 之和
–select AVG(prod_price) as avg_price
–from Products
–where vend_id=1001
–获取行数
–select COUNT(*) as num_cust
–from Customers
–组合聚合函数
–select COUNT(*) as num_item,
–min(prod_price) as price_min,
–MAX(prod_price) as price_max,
–AVG(prod_price) as price_avg
–from Products