7:mysql表查询数据select

查询语法

select  列 1, 列 2,... 列 n

from  表名

where 条件

 

  1. 1. 查询表的多有行所有列
  2. select * from user;
  3. 开发中很少这样写 , 因为表中会有成千上万的数据 , 这样查询会增加数据库负担
  4. 2. 查询一行
  5. select * from user where id=12;
  6. 3. 查询多行
  7. select * from user where id>=12;
  8. 4. 查询某几行的某几列 ,*  代表所有列
  9. select name,age from user where uid>=12;
  10. select name from user where uid=12;
  11. 5. 列是变量
  12. 每一行 , 变量值在变
  13. 从上到下 , 遍历行 ,where  是表达式 , 当 值为真 , 则取出该行
  14. select * from user where 1; // 取出所有行
  15. select * from user where 0; // 一行都取不出来
  16. 6. 变量可以计算
  17. select name,age+1 from user where 1;

mysql 表查询

提示:

大胆的把列看成变量 , 参与运算 , 甚至调用函数来处理 ,如:substring(),concat()等,

  1. select goods_id,substring(goods_name,4) from goods where goods_name like '诺基亚%';
  2. select goods_id,concat('HTC',substring(goods_name,4)) from goods where goods_name like '诺基亚%';
  3. update goods set goods_name=concat('HTC',substring(goods_name,4)) where goods_name like '诺基亚%';

 

注意:后面的教程会用上goods等相关表,goods是ecshop默认的ecs_goods表修改而来的,因为这个表比较全面,可以用来做查询测试;如果没有相关表的;

请点击百度网盘链接下载: http://pan.baidu.com/s/1geAomUf 密码: zad4

    A+
发布日期:2017年01月15日 16:56:30  所属分类:mysql教程
最后更新时间:2017-01-17 16:11:03
付杰
  • ¥ 99.0元
  • 市场价:99.0元
  • ¥ 298.0元
  • 市场价:398.0元
  • ¥ 199.0元
  • 市场价:299.0元
  • ¥ 199.0元
  • 市场价:499.0元

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: