zoukankan      html  css  js  c++  java
  • 数据库基本操作

    创建表:

    create table test (a varchar(20) NOT NULL,b int,primary key(a));

    删除表:

    drop table test

    清空表:

    truncate table test

    增加数据:

    insert into test (a,b) value('a',5)

    如果某个字段写入为空,或者用默认写入值,则,insert into test (a,b) value('',5),这样,给个空

    删除数据:

    delete from test where a='a'

    删除满足多个条件

    delete from test where a='a' and b='b' and c='c'

    修改数据:

    update test set a='b' where a='a'

    同时修改两个字段

    update test set a='b',c='b'  where a='a'

    按两个条件查找后同时修改多个字段

    update test set a='b',c='b'  where a='a' and b='b'

    查询数据:

    select * from test where a='b' and b=5

     统计数据:

    select count(column) from test

    查column在test表中有多少行

    select count(distinct column) from test 

    查 不重复的column 在test表中有多少行

    数据分组

    分组一般会与其他筛选一起用,比如说上面的count

    select count(column) from test group by date

    查以date分类后,不同date下column条数

    select count(column) from test group by date,date1

    查以date,date1分类,只要这一条数据的date和date1不是都相同,就算做不同数据

    模糊查询

    1,% :表示任意0个或多个字符。可匹配任意类型和长度的字符,有些情况下若是中文,请使用两个百分号(%%)表示。

    比如 SELECT * FROM [user] WHERE u_name LIKE '%三%'

    将会把u_name为“张三”,“张猫三”、“三脚猫”,“唐三藏”等等有“三”的记录全找出来。

    另外,如果需要找出u_name中既有“三”又有“猫”的记录,请使用and条件
    SELECT * FROM [user] WHERE u_name LIKE '%三%' AND u_name LIKE '%猫%'

    若使用 SELECT * FROM [user] WHERE u_name LIKE '%三%猫%'
    虽然能搜索出“三脚猫”,但不能搜索出符合条件的“张猫三”。

    统计不重复数据

    SELECT COUNT(DISTINCT column(s)) FROM table

    联合查询
    https://www.cnblogs.com/coocochoco/p/14198649.html#_label0
  • 相关阅读:
    PHP cURL 应用
    CURL的学习和应用
    PHP中使用cURL实现Get和Post请求的方法
    免费的论文查重网站
    免费的论文查重网站
    初识MFC学习——Hello World
    N皇后问题--回溯法
    c/c++工程中外部头文件及库添加方法
    WinDriver&PCIE
    初识-----基于Socket的UDP和TCP编程及测试代码
  • 原文地址:https://www.cnblogs.com/mghhzAnne/p/10616527.html
Copyright © 2011-2022 走看看