-- 查询语句select class from stu_info where sid=1000000102;select * from stu_info t where t.age=88; -- t是表的别名,多表查询时比较方便select * from atable a, btable b where a.aID = b.bID;select * from stu_info t where t.age=99 or (t.age>20 and t.age <90);select * from…
一.mysql中的GROUP BY和HAVINGGROUP BY常见的是和聚合函数(SUM,MIN,MAX,COUNT)搭配使用. 比如:SELECT category,SUM(money) AS `total` FROM user_money GROUP BY category;按类别分组统计user_money表每个类别总计有多少money 现在如果增加个条件,需要统计每个类别中支出的money总量,比如rule=1为支出,则改写语句为SELECT category,SUM(money) A…
从一个表中选取数据插入到另一个表中: select column_name(s) into new_table_name from old_table_name --new_table_name表不必事先存在(复制旧表的架构和数据) --只复制旧表架构 identity与select into合用,插入行号: set identity_insert students on , , 'newyank') set identity_insert students off --注意:一张表中只能有一列…
1.查询语句: SELECT 查询字段 FROM 表名 WHERE 条件 查询字段可以使用 通配符* 字段名 别名(把长的名字命名一个别名,比较短的) 通配符:SELECT * FROM 'phpdb' 字段名:SELECT id FROM ‘phpdb’ 别名:SELECT username AS un FROM ‘phpdb’ 常用条件: = 等于 .<>不等于.in 包含 . not in 不包含. like匹配 .BETWEEN在范围 . not BETWEEN不在范围 …