GP数据库 常用SQL语句 --1,查看列名以及类型 select upper(column_name) ,data_type from information_schema.columns where table_schema='ods_hs08' and lower(table_name)=lower('T_ods_hs08_secumreal'); --2,查看表名剔除分区表名 select a.tablename from pg_tables a where a.schemaname='…
第1章 数据库 1.1 数据库概述 l 什么是数据库 数据库就是存储数据的仓库,其本质是一个文件系统,数据按照特定的格式将数据存储起来,用户可以对数据库中的数据进行增加,修改,删除及查询操作. l 什么是数据库管理系统 数据库管理系统(DataBase Management System,DBMS):指一种操作和管理数据库的大型软件,用于建立.使用和维护数据库,对数据库进行统一管理和控制,以保证数据库的安全性和完整性.用户通过数据库管理系统访问数据库中表内的数据. l 常见的数据库管理系统 MY…
子查询 子查询要解决的问题,不能一步求解 分为: 单行子查询 多行子查询 语法: SELECT select_list FROM table WHERE expr operator (SELECT select_list FROM table); 子查询(内查询)在住查询之前一次执行完成 子查询的记过被主查询使用(外查询) 注意: 1.括号 2.合理的书写风格 3.可以在住查询的 WHERE SELECT HAVING FROM 后面使用子查询 4.不可以在GROUP BY 后面使用 5.强调F…
笔者日常工作中常用到的sql语句,现总结如下,留作日后查看. 1.按照两列中的最大值取 ,只取两列其中的一列 SELECT * FROM t_doc T ORDER BY GREATEST(T.Load_Count,T.Read_Count) desc 2.取两列之和 select t.*,(nvl(T.Load_Count,0)+nvl(T.Read_Count,0 )) as c FROM t_doc T order by c desc 3.取两列字符串连接 select T.Load_Co…
显示所有的数据库 show databases; 新建数据库 create database if not exists 数据库名 default character set = 'utf8'; 删除数据库 drop database (if exists) 数据库名; 使用表 use 数据库名; 新建表 create table if not exists 表名( id int unsigned primary key auto_increment, name varchar(10), ge…
$model=M(''); $model->table(C('DB_PREFIX').'goods as g') ->join(C('DB_PREFIX').'orders as o on o.goods_id=g.id') ->where('o.user_id='.$userid.' and o.state=1 and o.id not in(select c.order_id from '.C('DB_PREFIX').'comment as c where c.user_id='.…
一.mysql用户管理 grant all on *.* to 'user1'@‘127.0.0.1’ identified by 'mimA123'; 创建user1用户 使用user1登录 /usr/local/mysql/bin/mysql -uuser1 -pmimA123 -h127.0.0.1 变为localhost,不加-h也能登录 mysql> grant all on *.* to 'user1'@'localhost' identified by 'mimA123'; [ro…
1.MySQL用户管理 给远程登陆用户授权:grant all on *.* to 'user1'@'127.0.0.1' identified by '123456' (这里的127.0.0.1是指远程登陆的IP,即允许哪个IP登陆) 远程登陆的方式:mysql -h IP -u username -p 然后接着输入密码,就可以登陆了 用show grants; 命令,可以查看当前用户,所授权的大小:以及创建时的命令,可以复制后,再进行授权给其它用户 若要查看其它用户的授权,就需要用命令…