标签:别名 .com bst 不同 时间 str mon ati title
例子:vendors表包含供应商名和位置信息。假如要生成一个供应商报表,需要在供应商的名字中按照name(location)这样的格式列出供应商信息。此报表需要单个值,而表中数据存储在两个列vend_name和vend_country中,此外,需要用括号将vend_country括起来,这些东西都没有明确存储在数据表中,我们来看看怎么样编写返回供应商名和位置的select语句
SELECT CONCAT(vend_name, ‘ (‘,vend_country,‘)‘) FROM vendors ORDER BY vend_name;
这里用到了concat函数,拼接串,即把多个串连接起来形成一个较长的串,concat需要一个或者多个指定的串,各个串之间用逗号分隔
SELECT CONCAT(RTRIM(vend_name),‘ (‘,RTRIM(vend_country),‘)‘) FROM vendors ORDER BY vend_name;
rtrim函数去掉值右边的所有空格,通过使用rtrim(),各个列都进行了整理
SELECT CONCAT(RTRIM(vend_id),‘ (‘,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 expanded_price FROM orderitems WHERE order_num = 20005;
upper()函数
SELECT vend_name ,UPPER(vend_name) AS vend_name_upcase FROM vendors ORDER BY vend_name;
函数 说明
Left() 返回串左边的字符
Length() 返回串的长度
Locate() 找出串的一个子串
Lower() 将串转换为小写
LTrim() 去掉串左边的空格
Right() 返回串右边的字符
RTrim() 去掉串右边的空格
Soundex() 返回串的soundex值
SubString() 返回子串的字符
upper() 将串转为大写
SELECT cust_name , cust_contact FROM customers WHERE SOUNDEX(cust_contact)=SOUNDEX(‘Y lie‘);
查找与lie发音相似的cust_contact的列
SELECT cust_id , order_num FROM orders WHERE order_date = ‘2005-09-01‘;
SELECT cust_id , order_num FROM orders WHERE DATE(order_date) = ‘2005-09-01‘;
SELECT cust_id , order_num ,order_date FROM orders WHERE DATE(order_date) BETWEEN ‘2005-09-01‘ AND ‘2005-09-30‘;
SELECT cust_id ,order_num,order_date FROM orders WHERE YEAR(order_date)= 2005 AND MONTH(order_date)= 9;
9月份的所有订单
SELECT CONCAT(vend_name, ‘ (‘,vend_country,‘)‘) FROM vendors ORDER BY vend_name; SELECT CONCAT(RTRIM(vend_name),‘ (‘,RTRIM(vend_country),‘)‘) FROM vendors ORDER BY vend_name; SELECT CONCAT(RTRIM(vend_id),‘ (‘,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 expanded_price FROM orderitems WHERE order_num = 20005; SELECT vend_name ,UPPER(vend_name) AS vend_name_upcase FROM vendors ORDER BY vend_name; SELECT cust_name , cust_contact FROM customers WHERE SOUNDEX(cust_contact)=SOUNDEX(‘Y lie‘); SELECT cust_name , cust_contact FROM customers; SELECT cust_id , order_num FROM orders WHERE order_date = ‘2005-09-01‘; SELECT cust_id , order_num FROM orders WHERE DATE(order_date) = ‘2005-09-01‘; SELECT cust_id , order_num ,order_date FROM orders WHERE DATE(order_date) BETWEEN ‘2005-09-01‘ AND ‘2005-09-30‘; SELECT cust_id ,order_num,order_date FROM orders WHERE YEAR(order_date)= 2005 AND MONTH(order_date)= 9;
标签:别名 .com bst 不同 时间 str mon ati title
原文地址:http://www.cnblogs.com/kafeikele/p/6095913.html