SQLite轻量级数据库,操作数据常用语句
生活随笔
收集整理的這篇文章主要介紹了
SQLite轻量级数据库,操作数据常用语句
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
-----創(chuàng)建表---- ----------表格頭英文換中文顯示select?name?as?'名字',age?年齡,class?from?student -----if?not?exists判斷表存在否--字符串用char也行--- --如果用自增長,只能用包裝類型integer,不能用int-- create?table?if?not?exists?student(id?Integer?primary?key??autoincrement?not?null,????????name?String?not?null,???????sex??String?not?null,?????????age??int?not?null,?????????hight?real?,????????class??String ) ------用逗號分隔,最后一個字段不用寫----- ---刪除表------ drop?table?student ------插入一條數據------ insert?into?student?(name,sex,age,hight,class)?values('張三','男',21,178,'cc111') ------插入多條數據------ insert?into?student?(name,sex,age,hight,class)?values('李四','男',23,170,'cc111'),('王五','女',20,173,'cc111') ,('趙六','男',22,179,'cc112'),?('朱七','女',24,171,'cc112') ------查詢所有數據------ select?*?from?student ------------------- select?*?from?student?where?age=22 ------修改數據------ ----?update?表名??set?字段?=-加條件?where?--- update?student?set?hight=null?where?id=5 -----班級為cc111,男,hight不為null,則每個高度都增長1 update?student?set?hight=hight+1?where?class='cc111'?and?sex='女'?and?hight?not?null ---------------凡是cc111班年齡減1----update?student?set?age=age-1?where?class='cc111'? -------------凡是cc111班或者性別為女的則高度+1----------------------update?student?set?hight=hight+1?where?class='cc111'?or?sex='女'? --------修改名字的第一個字為王的年齡減1歲 update?student?set?age?=age-1?where?name?like?'王%' -----------修改名字為張三或者為李四的班級為cc112---------------- update?student?set?class='cc112'?where?name?in('張三','李四') ----刪除所有 delete?from?student -------刪除名字含朱的 delete?from?student?where?name?like?'%朱%' --查詢所有 select?*?from?student ---女的 select?*?from?student?where?sex='女' ------查詢cc111班的人的名字 select?name?from?student?where?class='cc111' --查詢大于21,小于23的人 select?*?from?student?where?age>=21?and?age<=23 ---查詢名字含朱的 select?*?from?student?where?name?like?'%朱%' ---------查詢cc111班女生,并且按年齡從小到大排序-??order?by,降序?desc,默認就是升序- select?*?from?student?where?sex='女'?and?class='cc111'?order?by?age?desc -------------查詢所有女生,并且按年齡從大到小排序-,只顯示前3個---- ----limit?偏移量0表示第一個,顯示的個數-----? select?*?from?student?where?sex='女'?order?by?age?desc?limit?0,2 ---查詢出cc112班的總人數-------- select?count(*)?from?student?where?class='cc112' ------查詢出cc112班的所有人的年齡總和--------------- select?sum(age)?from?student?where?class='cc112' -------查詢出cc111班的平均年齡------------- select?avg(age)?from?student?where?class='cc112' -----查詢所有的班級的男性人數,并且按班級進行分組?group?by?--------- select?class,count(*)?from?student?where?sex='男'?group?by?class -----查詢cc112班年齡最大的學員----------- select?max(age),name?from?student?where?class='cc112' -----查詢班上的所有學員,按班級進行分組,再進行降序,并且只列出總人數大于等于1個班級----------- select?class,count(*)?from?student? group?by?class?having?count(*)>=1?order?by?count(*)?desc轉載于:https://my.oschina.net/u/2541146/blog/551994
總結
以上是生活随笔為你收集整理的SQLite轻量级数据库,操作数据常用语句的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微型计算机原理与接口周荷琴,微型计算机原
- 下一篇: ascll编码表图片_ascii码对照表