1. # alter语句中在声明列的名称时,使用 after column 指定插入列的位置,first 为指定在列表的第一列
first 插在表第一列
after column名(插入指定的列后面)
2. # not、 and、 or的优先级, not > and > or
select * from class where not A and B > x or C < y and D = z; # where 句子视为表达式,按照 not and or 进行执行
3. # MySQL 中,column看做是变量,where 句子视作条件判断句,where(条件句)中为真,则执行语句
tips: 这里着重要理解 select 查询语句 的模型,各个 column 看做是个变量,将where句子看成是 if (exp)的表达式
# column 可以进行逻辑、算术运算
eg: select a, b, (a - b) from table where ();
select a, b ,(a - b) as c from table where ();
select a, b ,(a - b) as c from table where 1; # where 1 即为真,table全取
4. # 将 goods_name 中 名称为“诺基亚”开头的数值替换为 ‘HTC’
# 取出‘诺基亚’开头的 select * from goods where goods_name like ‘诺基亚%’;
% : 通配符,可以替代任意字符
_ : 替代单一字符
eg : select goods_name , concat('HTC',substring(goods_name,4) from goods
where goods_name like '诺基亚%';
# substring (column,len),len是截取的长度;
5. # 经典的题目
在table名为test的数据表中,将num值处于[20,29]的数值改为20,将num值处于[30,39]间的数值改为30;
提示: num/取整* 10