SQL常用语句+举例

上传人:jun****875 文档编号:18671282 上传时间:2021-01-02 格式:DOC 页数:8 大小:85.41KB
返回 下载 相关 举报
SQL常用语句+举例_第1页
第1页 / 共8页
SQL常用语句+举例_第2页
第2页 / 共8页
SQL常用语句+举例_第3页
第3页 / 共8页
点击查看更多>>
资源描述
SQL常用语句+举例相关表:Store_information表Store_namesalesdateLos Angeles$1500Jan-05-1999San Diego$250Jan-07-1999Los Angeles$300Jan-08-1999Boston$700Jan-08-1999Geography表Region_nameStore_nameEastBostonEastNew YorkWestLOS AngelesWestSan Diego1. distinct: 剔除重复记录例:select distinct stroe_name from Store_informationStore_nameLos AngelesSan DiegoBoston结果:2. And / or: 并且/或 例:在表中选出所有sales 高于$1000或是sales在$275及$500之间的记录Select store_name ,sales from Store_information Where sales1000Or (sales275 and sales $1500store_namesum(sales)Los Angeles$1800结果:11. Alias :别名,字段别名和表格别名语法:select 字段名 AS 字段别名 from 表名 AS 表别名例:select store_name AS store from Store_information AS S1结果 :storeLos AngelesSan DiegoLos AngelesBoston12. 左连接/内部连接例:查找每一区域的salesSelect A2.Region_name,A1.sales from Geography AS A2,Store_information AS A1Where A1.store_name=A2.store_nameGroup by A2.Region_nameregionsaleseast$700west$2050结果:13. 外部连接 : +例:我们需要查找每一个店的营业额,如果我们用一个普通连接,就会漏掉 new york这个店,这时我们要用外部连接Select A1.store_name ,sum(A2.sales) from eography AS A1,Store_information AS A2Where A1.store_name=A2.store_name(+)Group by A1.store_name14. Creat table:创建表Creat table custome(first_name char(50),Lat_name char(50),Birth_date date)15. Creat view:创建视图Creat view V_customeAS select first_name,last_name from custome16. Creat index:创建索引Creat index idx_custome_last_name on custome(last_name)17. Alter table:修改表加一个字段:Alter table custome add gender char(2)删除一个字段:Alter table custome drop gender 改变字段名称:Alter table custome change first_name f_name char(50)改变字段类型:Alter table custome modify first_name char(30)18. Primary key:主键,不能为空Alter table custome add primary key(sid)19. 外键:指向另一个表主键的字段Creat table users(u_id int,U_name char(20)Primary key(u_id)Foreign key(u_name) references custome(sid)20. Truncate table 表名:清除表中数据21. Insert into:向表中插入记录Insert into stroe_information (store_name,sales,date) values (piny,$900,jan-10-1999)22. Update:更新记录Update stroe_informationSet sales=$600Where store_name=los angelesAnd date=jan-08-199923. Delete:删除记录Delete from stroe_information where store_name=los angeles
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 大学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!