查询姓“猴”的学生:

% 表示任意字符串

  1. -- 查询姓猴的学生名单
  2. select *
  3. from student
  4. where name like "猴%" // %号表示任意字符串
  5. -- 查询最后一个是猴的学生名单
  6. select *
  7. from student
  8. where name like '%猴'
  9. -- 查询包含是“猴”的学生名单
  10. select *
  11. from student
  12. where name like "%猴%"
  13. --- 查询姓 “梦”老师的个数 count 指的是个数
  14. select count // 数量
  15. from student
  16. where name lime "%梦"
  17. --- 查询课程编号为“0002”的总成绩
  18. select sum(成绩) // 汇总数量
  19. from course
  20. where 课程号 = 0002
  21. --- 查询选了课程的同学
  22. select count(distinct 学号) as 学生人数
  23. from course
  24. where 课程号= '0002'
  25. select name,country
  26. from Websites
  27. select *
  28. from Websites
  29. select distinct country
  30. from Websites
  31. select *
  32. from Websites
  33. where country = 'CN'
  34. 文本字段 vs. 数值字段
  35. SQL 使用单引号来环绕文本值(大部分数据库系统也接受双引号)。
  36. 在上个实例中 'CN' 文本字段使用了单引号。
  37. 如果是数值字段,请不要使用引号。
  38. SQL AND & OR 运算符
  39. 如果第一个条件和第二个条件都成立,则 AND 运算符显示一条记录。
  40. 如果第一个条件和第二个条件中只要有一个成立,则 OR 运算符显示一条记录。
  41. select
  42. from Websites
  43. Where counry = 'CN' and alexa > 50;
  44. select
  45. from Websites
  46. Where country = 'USA' or conntry = 'CN';
  47. select
  48. from Websites
  49. Where alexa = 15
  50. and (country = "USA" or country = 'CN')
  51. select *
  52. from Websites
  53. order by alexa
  54. select *
  55. from websites
  56. order by alexa desc
  57. insert into table_name
  58. values(value1,value2,value3);
  59. insert into table_name(column1,column2,column3)
  60. values(value1,value2)
  61. insert into websites(name,url,alexa,country)
  62. values('百度','http.wwww','4','CN')
  63. update table_name
  64. set column1 = value1,column2 = value2
  65. where some_colum = some_value;
  66. update websites
  67. set alexa = 5000,country = USA
  68. where name = "菜鸟教程"