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前面

  • 相关阅读:
    [转]XSLT <xsl:output> 元素
    XSLT教程
    [转]web.xml文件中配置<mimemapping>下载文件类型
    IntelliJ IDEA 付费版 免费版比较
    tomcat 显示隐藏目录结构
    XHTMLMP 7788
    [转]HttpSessionListener 和HttpSessionBindingListener的区别
    error LNK2005: _DllMain@12 已经在 LIBCMTD.lib(dllmain.obj) 中定义
    请确保在应用程序配置的 \\ 节中包括 System.Web.SessionStateMod 或自定义会话状态模块
    NuGet 是个什么玩意?
  • 原文地址:https://www.cnblogs.com/naqiang/p/5530832.html
Copyright © 2011-2022 走看看