zoukankan      html  css  js  c++  java
  • mysql rdms 笔记

    创建表

    mysql> create table test(name varchar(20) not null);
    mysql> alter table test add column id int auto_increment not null, add primary key(id);
    mysql> describe test;

    插入数据到表格

    insert into members ( firstname, lastname, memberid ) values( "zzz", "sss", 1);

    删除字段

    delete from userlist where (name = "${getParseData.name}") and (age > 18)

    Note:之前from进入查询提取列表的排列信息, where进入查询特定子集, where命令使用逻辑运算符指定要返回那些行如WHERE nameValue = 369, 如果是字符串使用”引号, 数字不需要引号. 模糊查询多个子集, 使用括号分割每个逻辑字段, 其中括号分割使你查询更容易理解, and 和 or 命令进行组合多个逻辑条件.

    查询前n行记录

    select * from table limit 0,n;

    查询最后一条Permalink

    select id from table where id>1,name=1 order by id desc limit 1

    Note:了解最后一个命令 order by, 这个命令允许我们在给定的列上对数据库进行排序, 后面给需要排序字段的名称. 默认情况下, 按照升序排列; 其中asc为升序如ORDER BY id asc, desc为降序如ORDER BY id desc. 其中给定命令limit为输出限制 1 行数量.

    查询多个字段的模糊搜索

    select * from user where realname like '%龙%' and realname like '%文%'

    模糊查询加分页

    select * from userlist where name like "%${search_data}%" and id limit ${10 * (page_index-1) } , ${10}

    多表查询Permalink

    select userList.name, testList.type from userList INNER JOIN testList ON userList.member_id = testList.member_id

    Note:列表和字段关联编写..使用逗号分隔表名和列名,如select name, type from会写成select userList.name, testList.type from, 此处关联表名表示告诉数据库要查找每个表来查找每个表的列.from查找表名后面紧接着join指定应该连接哪些表并on指定每个表中哪些列是相关的.

    https://koringz.github.io

    如需转载原创文章,请标注原文地址,版权所有!
  • 相关阅读:
    Python class static methods
    学习MySQL出现问题Not allowed to return a result set from a t
    MySQL创样例表(MySQL必知必会B.2)
    无重复字符的最长字串(C++,python实现)
    softmax详解
    为什么要使用logistic函数
    两个栈实现队列的插入和删除(C++实现)
    用数组实现队列(C++)
    C++ memset函数
    两数之和(C++实现)
  • 原文地址:https://www.cnblogs.com/hao5599/p/14963852.html
Copyright © 2011-2022 走看看