选择:
select * from user where user.id=1;
插入:
insert into user(user.id,user.name,user.pwd) values('3','testname','testpwd')
insert into booktest(booktest.id,booktest.name,booktest.price,booktest.userid) values(1,'好书名',15,null)
删除:
delete from user where id=3
更新:
update user set user.name='updatename' where user.id=2
Like语句:
select * from user where user.name like '%name%'
排序:
select * from user order by user.id desc
总数:
select count(*) from user
求和:
select sum(book.price) from book
平均:
select avg(book.price) from book
最大:
select max(book.price) from book
最小:
select min(book.price) from book
left join:
select * from user u left join book b on u.id=b.userid;
Group by:
select u.id,u.name,count(*) from user u left join book b on u.id=b.userid group by u.id;
IN:
select * from book where price in(25,10)
NOT IN:
select * from book where price not in(25,10)
子查询:
select * from user where user.id in(select book.userid from book)
Between:
select * from book where book.price between 5 and 30
时间函数:
select DAYOFWEEK('1998-02-03');
select WEEKDAY('1997-10-04 22:23:00');
创建表
CREATE TABLE booktest (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(1024) NOT NULL,
price int(10) not null,
userid int(10)
)
TABLESPACE ts_1 STORAGE DISK
ENGINE NDBCLUSTER;