SQL
SQL
Loong Tu
这个作者很懒,什么都没留下…
展开
-
13. 创建和操纵表
文章目录创建表 创建表 CREATE TABLE products_test ( prod_id char(10) NOT NULL, vend_id char(10) NOT NULL, prod_name char(255) NOT NULL, prod_price decima...原创 2020-02-28 18:25:49 · 100 阅读 · 0 评论 -
12. 更新和删除数据
文章目录本节使用的表customers更新数据删除数据 本节使用的表 customers postgres=# \d customers Table "public.customers" Column | Type | Collation | Nullable | Default --------------+------...原创 2020-02-23 22:59:47 · 183 阅读 · 0 评论 -
11. 插入数据
文章目录本节使用的表customers插入完整的行 本节使用的表 customers postgres=# \d customers Table "public.customers" Column | Type | Collation | Nullable | Default --------------+--------...原创 2020-02-21 23:06:39 · 162 阅读 · 0 评论 -
10. 组合查询
文章目录本节使用的表customers定义创建组合查询单条语句多个WHEREUNION包含重复的行对组合查询结果排序UNION规则 本节使用的表 customers postgres=# \d customers Table "public.customers" Column | Type | Collation | Nu...原创 2020-02-20 23:07:20 · 147 阅读 · 0 评论 -
9. 创建高级联结
文章目录本节使用的表vendorsproductscustomersordersorderitems使用表别名自联结子查询的方法自联结的方法 本节使用的表 vendors postgres=# \d vendors Table "public.vendors" Column | Type | Collation | Null...原创 2020-02-14 22:43:24 · 112 阅读 · 0 评论 -
8. 联结表
文章目录 postgres=# \d vendors Table "public.vendors" Column | Type | Collation | Nullable | Default --------------+---------------+-----------+----------+--------- ve...原创 2020-02-10 20:20:17 · 200 阅读 · 0 评论 -
7. 使用子查询
文章目录利用子查询进行过滤作为计算字段使用子查询 利用子查询进行过滤 select order_num from orderitems where prod_id = 'RGAN01'; order_num ----------- 20007 20008 (2 rows) select cust_id from orders where order_num in (200...原创 2020-02-03 21:51:50 · 99 阅读 · 0 评论 -
6. 分组数据
分组数据创建分组过滤分组分组和排序SELECT子句顺序 创建分组 select vend_id from products; vend_id ------------ BRS01 BRS01 BRS01 DLL01 DLL01 DLL01 DLL01 FNG01 FNG01 (9 rows) select vend_id from products group by v...原创 2019-09-08 23:12:17 · 122 阅读 · 0 评论 -
5. 汇总数据
汇总数据聚集函数AVG()函数COUNT()函数MAX()和MIN()函数 聚集函数 函数 说明 AVG() 返回某列的平均值 COUNT() 返回某列的行数 MAX() 返回某列的最大值 MIN() 返回某列的最小值 SUM() 返回某列值之和 AVG()函数 AVG()函数忽略列值为NULL的行。 select avg(prod_price) as avg_...原创 2019-09-08 20:45:37 · 153 阅读 · 0 评论 -
4. 使用函数处理数据
使用函数处理数据文本处理函数日期和时间处理函数数值处理函数 文本处理函数 常用的文本处理函数: 函数 说明 备注 LEFT() 返回字符串左边的字符 或使用子字符串函数 LENGTH() 返回字符串的长度 也使用DATALENGTH()或len() LOWER() 将字符串转换为小写 LTRIM() 去掉字符串左边的空格 RIGHT() 返回字符串右边的字符 或...原创 2019-09-08 17:47:45 · 127 阅读 · 0 评论 -
3. 创建计算字段
创建计算字段拼接字段 postgres=# select * postgres-# from vendors; vend_id | vend_name | vend_address | vend_city | vend_state | vend_zip | vend_country ------------+-----------------...原创 2019-09-08 15:43:23 · 177 阅读 · 0 评论 -
2. 过滤数据
过滤数据空值检查组合where子句IN操作符NOT操作符通配符 空值检查 select cust_name, cust_email from customers where cust_email is null; cust_name | cust_email ---------------------------...原创 2019-09-08 15:10:23 · 153 阅读 · 0 评论 -
1. 检索数据
postgres=# \d products Table "public.products" Column | Type | Collation | Nullable | Default ------------+-------------------------+-----------+------...原创 2019-09-08 14:52:53 · 155 阅读 · 0 评论