mysql笔记
创建数据库
create database dbtest1
查
查询数据库通用语法:
select columnName,columnName1 from dbname.tablename [where clause] [order by] [limit N];
查看表格所有列:
select * from dbname.tablename;
查看某一列和:
select SUM(columnName) from dbname.tableName;
多表联合查找
select table1.column1,table1.column2 from table1 left join table2 on table1.column3=table2.column3 where table1.column4='test';//left join以左表为主,获取左表所有记录,即使右表没有匹配记录,
right join相反,以右表为主,获取右表所有记录,inner join则获取量表中字段完全匹配关系的记录
单一条件联合查找
select * from table 1 where column1 = (select column1 from table2 where column3>0);
条件查找之if语句
select ( case when column1 + column2 = column3 then 'true' when column1 + column2 != column3 then 'false' end) as result from table1 where column>0;
查看表行数
select count(*) from table1;
排序,限行数
select * from table1 order by column1 desc limit 10; //按column1倒叙排列,取前10行