您的位置:首页 > 数据库

sqlite数据库基本操作

2016-01-02 00:00 417 查看
1:html:超文本标记语言。里面有很多标记:主要是做静态页面。
静态页面:什么时候都是不变的。
动态页面:不同时间访问是不一样的,动态页面是在静态页面的基础上加了其他的web开发语言。asp.net,jsp,
2:html的文件都在浏览器里去查看的。浏览器才可以去解析这样的文件。
3:html文件的后缀是.html或者htm
4:sqlite数据库:移动系统的数据库,轻量级数据库。用户自己的数据库就在自己的手机上,所以就没有什么数据安全方面的问题。基本上都是单表操作。
sqlite数据库中的数据类型;String;字符串,Integer:整数。
null:空的,real:小数。blob:二进制数据。sqlite数据库中的数据都是由具体的值来确定的。

-----------------------------------------------------------------------------------------------------

------创建表结构-
-- sqlite的数据类型:text,integer,real,null,blob,----
----创建表的时候可以不写数据类型,数据库会根据具体值来确定它的数据类型。------------
create table if not exists student(
_id integer primary key autoincrement not null,
name string not null,
age integer not null,
height real,
sex string not null ,
classname string not null
)
----删除表------
drop table student
------往表里面添加数据。 insert into 表名(字段1,字段2) values(值1,值2)--------
------插入一条数据-------
insert into student(name,age,height,sex,classname)
values('小红',22,162,'女','and1505')
-----插入多条数据-------
insert into student(name,age,sex,height,classname)
values('李丰',23,'男',180,'and1510'),
('小燕',22,'女',159,'and1505')
------查询表中的数据---------------
-------查询所有的数据 select-------------
select * from student
------修改数据------
---- update 表名 set 字段 =值-------------
update student set height=163 where _id=7
------班级为and15010,男,height不为null,则每个高度都增长1
update student set height = height+1
where classname='and1510'
and sex='男'
and height not null
---------------凡是1510班年龄减1----
update student set age = age-1 where classname='and1510'
-------------凡是1510班或者性别为女的则高度+1----------------------
update student set height = height+1
where classname='and1510'
or sex='女'
--------修改名字的第一个字为小的年龄减1岁------------------------
update student set age =age-1
where name like '小%'
---------修改名字为小谢或者为小红的班级为and1511-----------
update student set classname='and1511'
where name='小王' or name='小谢'
-----------修改名字为小谢或者为小红的班级为and1510----------------
update student set classname='and1510'
where name in ('小王','小谢')
--------修改名字的第一个字为小字变成大字---------------
update student set name = replace(name,'小','大')
where name like '小%'
------------删除数据 delete from 表名 where ---------------------
--------删除高度为null的数据-------
delete from student where height is null
select * from student
------删除所有的数据----------
delete from student
----------删除名字含有'燕'的记录-----------------
delete from student where name like '%燕%'
----------删除高度小于160的记录------------
delete from student where height<160
-------查询 select 字段 from 表---------------------
--------查询性别为女的-----------------
select * from student where sex='女'
---------查询所有的---------------
select * from student
-----查询and1510班的学生的姓名------------
select name from student where classname='and1510'
-------查询年龄20-25之前的学生-----------------
select * from student where age>=20 and age<=25
-------------查询名字里含有大的学生--------------------------------
select * from student where name like '%大%'
---------查询and1510班女生,并且按年龄从小到大排序- order by,降序 desc,升序asc,默认就是升序---------------------
select * from student
where sex='女'
order by age desc
-------------查询所有女生,并且按年龄从小到大排序-,只显示前3个----
----limit 偏移量0表示第一个,显示的个数-----
select * from student
where sex = '女'
order by age
limit 1,3
---查询出1510班的总人数--------
select count(*) from student where classname='and1510'
------查询出1510班的所有人的年龄总和---------------
select sum(age) from student
where classname='and1510'
-------查询出1510班的平均年龄-------------
select avg(age) from student
where classname='and1510'
-----------------查询所有的班级的男性人数,并且按班级进行分组 group by ---------
select classname,count(*) from student
where sex = '女'
group by classname
-----查询1510班年龄最大的学员-----------
select max(age),name from student
where classname='and1510'
------查询1505班年龄最小的学员--------
select min(age) ,name from student
where classname='and1505'
-----查询班上的所有女学员,按班级进行分组,再进行降序,并且只列出总人数大于等于1个班级-----------
select classname ,count(*)
from student
where sex='女'
group by classname
having count(*)>=1
order by count(*) asc
-------where---group---having---排序 ------------

---------------------------------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: