zoukankan      html  css  js  c++  java
  • 数据库查询的几种方式

    1.增加内容 insert into Info values(‘p001’,‘张三’,true,‘n001’,‘1989-2-3’) insert into Info (code,name) values('p002','李四');

    2.删除数据 delete from Info where Code ='p002'

    3.修改数据 update Info set Name='李四' where Code='p001'

    4.查询数据 (1)简单查询

    select * from Info select Code,Name from Info select Code as‘代号’,Name as‘姓名’from Info查询指定列且替换了列名

    (2)条件查询 select *from Car where Code=‘c002’ true

    sekect * from Car where brand=‘b001’ and Powers=130 多条件查询  或者用or and是并且

    (3)模糊查询 select * from Car where Name like '%奥迪%' %代表任意多个字符 _代表一个任意的字符

    (4)排序查询 select * from Car order by Powers asc升序 desce降序 默认升序,所以可以不写asc(asc,desc) select * from Car order by brand asc, Powers desc asc可不写 双列排序 (5)范围查询 select * from Car where Price>=40 and Price<=60 select * from Car where Price between 40 and 60

    (6)离散查询 select * from Car where Code in ('c001',‘c003’,‘c005’,'c007') select * from Car where Code  not in('c001',‘c003’,‘c005’,'c007')

    (7)聚合函数 select sum(Price)from Car   #查询所有价格之和 素描()求和 不可用字符串 select count(*)from Car     #查询数据总条数 *可以替为列名   可用字符串

    select max(Price) from Car  #查询最大值 可用于字符串 select min(Price) from Car  #查询最小值 可用于字符串 select avg (Price)  from Car  #查询平均值 不可以用字符串 (8)分页查询条 #每页显示5条数据,取第2页的数据 select * from Car limit (n-1)*5,5 (9)去重查询 select distinct Brand from Car 去掉brand列的重复 (10)分组查询 select count(*) ,from Car group by Brand 分组查数量 select * from Car group by Brand having count (*)>3#分组之后根据条件查询使用having, 分组之后不使用where。使用where要写在group前面

  • 相关阅读:
    递归与尾递归总结
    JAVA基础——链表结构之双端链表
    JAVA基础——链表结构之单链表
    JAVA基础——集合Iterator迭代器的实现
    JAVA基础——Date和Calendar类
    JAVA基础——Native关键字
    Java基础——从数组到集合之间关键字的区别!!!!
    JAVA基础——集合类汇总
    Web前端性能优化——提高页面加载速度
    vue 与 angular 的区别
  • 原文地址:https://www.cnblogs.com/naqiang/p/5530832.html
Copyright © 2011-2022 走看看