sql语句学习

update

1、set一个字段
在表t_test中设置第二条记录(bs为2)的password为'***'。
update t_test t
   set t.password = '***'
where t.bs = 2;

http://lavasoft.blog.51cto.com/62575/27692

 

login

mysql -h 11.11.11.1 -u root -p

mysql -u root -p

view table field 

desc tablename

mysql> select host,user from mysql.user;
+-----------+-------------+
| host      | user        |
+-----------+-------------+
| %         | fishadmin   |
| %         | jiraadmin   |
| %         | root        |
| %         | udanceadmin |
| localhost | fishadmin   |
| localhost | jiraadmin   |
| localhost | jirauser    |
| localhost | root        |
+-----------+-------------+
8 rows in set (0.00 sec)


%意思任意主机都可以连接



android Sqlite

--update message set readstatus = 1 where sender = 13455556669 and receiver = 13455556667 and readstatus = 0;

--select * from message where readstatus <> 0;//readstatus不等于0的数据

--select * from message where sender='13455556661' and receiver='13455556663' and process=103 order by _id desc;
--select * from message limit 3;--只查询前三条数据
--select * from message limit 2,1;--指定偏移量和查询数据条数
select count(1) from message;--查询消息表中的数据条数


2.数据库查询语句
select * from message order by _id asc;按_id的升序
select * from message order by _id desc;按_id的降序
2.1
select sender,receiver,content from message group by sender order by _id desc;
当order by和group by一起使用的时候,要先用group by,再用order by


4.关于删除
从message表中删除_id=2的一条记录的SQL语句:
delete from message where _id = '2';
参考:http://blog.sina.com.cn/s/blog_69092aea0101879o.html
--select * from message order by _id desc;
--select * from message where sender = 'hello1' and receiver = 'hello2' or sender = 'hello2' and receiver = 'hello1';
--select * from message where sender = 'hello2' and receiver = 'hello1';
--CREATE TABLE IF NOT EXISTS temporder(_id INTEGER PRIMARY KEY AUTOINCREMENT, ordernumber text, ordertime text, appointtime text, appointstatus text, stationname text, serviceitem text,saname text, telephone text, rating text, commentcount text, isAuth INTEGER, carbrand text, carkind text, carnum text, carage text, carmiles text, worktime text, price text, shoplongi text, shoplati text);
--CREATE TABLE IF NOT EXISTS ordera (_id INTEGER PRIMARY KEY AUTOINCREMENT, ok text);
--select _id, appointstatus, appointtime, ordernumber, stationname, serviceitem, saname, telephone from repairorder where telephone=13566667777;


--delete from message where _id = '2';


--CREATE TABLE IF NOT EXISTS carinfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, carLogo INTEGER, carNum TEXT, carBrand TEXT, carLevel TEXT, carYear TEXT, phone TEXT);
--delete from message;
--select content from message where _id < 50 order by _id asc;
--select * from message group by sender;-- where readstatus = 0
--select * from message where receiver = 13455557777;
--update message set readstatus = 0 ;--where sender = 13455556667 and receiver = 13455557777;
--select * from message where readstatus=1 group by sender;
--delete from friendrequest;
--update friendrequest set agree=10 where reqfrom='13455556664' and reqto='13455556665';
--update friendrequest set agree = 13,icon='abc',added=32 where reqfrom= '13455556664' and reqto= '13455556665';
--select content from message;
--select _id from carinfo;
--update carinfo set carid = 110 where _id=12;
--delete from message;
--create table friends (username TEXT);
delete from friends where username = '13455556668' and jid='13455557777@iz280uotbvjz';

你可能感兴趣的:(sql语句学习)