SQL基本语法(四)多表查询

SQL基本语法(四)多表查询
多表查询   select albums.name,albums.year,artists.name from albums,artists;   SELECT * FROM albums JOIN artists ON albums.artist_id = artists.id;   SELECT * FROM albums LEFT JOIN artists ON albums.artist_id=artists.id;   select albums.name as 'Album',albums.year,artists.name as 'Artist' from albums join artists on albums.artist_id = artists.id where album...

SQL基本语法(三)计算

SQL基本语法(三)计算
  计数 SELECT COUNT(*) FROM table_name; 总数 select count(*) from table_name where price=0; 价格等于0的数量 select price, count(*) from table_name group by price; //Count the number of apps at each price.   select price,count(*) from table_name where column > 20000 group by price; SELECT SUM(column) FROM table_name;   SELECT category, SUM(column) FROM fake_...

SQL基本语法(二)查询

SQL基本语法(二)查询
  查询 SELECT * FROM table; SELECT column1,column2 FROM table; SELECT DISTINCT column FROM table; SELECT * FROM table WHERE id > 8; 其他符号(=、!=、>、<、>=、<=)   模糊查询 SELECT * FROM table where name LIKE 'Se_en'; 通配符(%) SELECT * FROM table WHERE name LIKE '%man%';   select * from movies where name between 'A' and 'J'; select * from mov...

SQL基本语法(一)基础

SQL基本语法(一)基础
基础   select * from table_name; select id from table_name   创建数据库表 CREATE TABLE table_name( column_1 data_type, column_2 data_type, column_3 data_type, );   eg: CREATE TABLE celebs1 (id INTEGER,name TEXT,age INTEGER);   添加一条记录 INSERT INTO table_name(id,name,age) VALUES(1,'dupeng',29);   修改一条记录 UPDATE table_name SET age = 22 where i...