2016-2-1整理
select CONCAT('bh',YHBH) AS YHBH,YHXM from sfjc_yw_ryxx where FYDM='1300B00' AND BZLX != '8' AND LKYY IS null and yhbh NOT IN (select yhbh from sfjc_jl_djlxr) ORDER BY NBPXH,cast(ZWMC as int)
SELECT * FROM SFJC.SFJC_YW_RYXX A left join sfjc.sfjc_xt_fy B on A.FYDM=B.FYDM LEFT JOIN sfjc.sfjc_v_wz_jxjb C on A.FYDM=C.FYDM AND a.yhbh=C.yhbh WHERE YHXM ="dddd"
select YHBH,YHXM from sfjc_yw_ryxx where FYDM='1300B00' and YHBH in (select yhbh from sfjc_jl_djlxr) ORDER BY NBPXH,cast(ZWMC as int)
ALTER table scfz_xewp add BGR varchar(255) after KYR
INSERT INTO scfz_clky (CLBH, AH, CPH, CLX, PGJ, PMJ, KYSJ, KYDD, BGR, CBR, LRYH, LRSJ, WJMC) VALUES ('CLKY-1510-00001', '345', '64', '121', '', '', '2015-10-15', 'rest', '风格', '1303B12140801001', '4', now(), '')
drop trigger sfjc.sfjc_yw_ryxx_before_update;
--/
CREATE DEFINER=`sfjc`@`%` TRIGGER `sfjc`.`sfjc_yw_ryxx_before_update`
BEFORE UPDATE ON
sfjc.sfjc_yw_ryxx
FOR EACH ROW begin
set new.xgsj=now();
if new.LKYY is not null then
update sfjc.sfjc_xt_user set sfqy=0 where yhbh=new.yhbh;
end if;
if new.LKYY is null then
update sfjc.sfjc_xt_user set sfqy=1 where yhbh=new.yhbh;
end if;
end
/
--/
CREATE DEFINER=`sfjc`@`%` TRIGGER `sfjc`.`sfjc_wz_lm_before_insert`
BEFORE INSERT ON
sfjc.sfjc_wz_lm
FOR EACH ROW begin
if new.cjsj is null then
set new.cjsj=now();
end if;
end
/
call web_list_proc('19',1,20,'')
java中调用时,
cStm = con.prepareCall(
"{call web_list_pf_proc('" + lmdm + "'," + curPage + ","
+ perPage + ",'"+aSearchKey+"','" + selectTimeWhere +"','" + sortTime + "')}");
CREATE DEFINER=`sfjc`@`%` PROCEDURE `sfjc`.`web_list_proc`(in lmdm varchar(10), in showPageNum int, in paginalLinage int, in keyWords varchar(255))
begin
declare countStmt varchar(200);
declare selectStmt varchar(300);
declare beginRecordNum int;
set @beginRecordNum=(showPageNum-1)*paginalLinage;
if lmdm='search' then
set @countSql = concat('select count(1) recNum from (select ID,BT FROM SFJC.SFJC_WZ_TPXW WHERE ',keyWords,' and xxzt=8 union select ID,BT FROM SFJC.SFJC_WZ_XXNR WHERE ',keyWords,' and xxzt=8) A ');
set @selectSql = concat('select ID,BT,FWCS,FBSJ,datediff(now(),FBSJ) FBTS,LMDM from (select concat(''sp='',ID) ID,BT,FWCS,FBSJ,LMDM FROM SFJC.SFJC_WZ_TPXW WHERE ',keyWords,' and xxzt=8 union select concat(''nsp='',ID) ID,BT,FWCS,FBSJ,LMDM FROM SFJC.SFJC_WZ_XXNR WHERE ',keyWords,' and xxzt=8) A ORDER BY FWCS DESC limit ',@beginRecordNum,',',paginalLinage);
elseif lmdm='0' then
set @countSql = concat('select count(1) recNum from (select ID,BT FROM SFJC.SFJC_WZ_TPXW WHERE FWSJ >DATE_ADD(now(), INTERVAL -11 DAY) and xxzt=8 union select ID,BT FROM SFJC.SFJC_WZ_XXNR WHERE FWSJ >DATE_ADD(now(), INTERVAL -11 DAY) and xxzt=8) A ');
set @selectSql = concat('select ID,BT,FWCS,FBSJ,datediff(now(),FBSJ) FBTS,LMDM,FWSJ from (select concat(''sp='',ID) ID,BT,FWCS,FBSJ,LMDM,FWSJ FROM SFJC.SFJC_WZ_TPXW WHERE FWSJ >DATE_ADD(now(), INTERVAL -11 DAY) and xxzt=8 union select concat(''nsp='',ID) ID,BT,FWCS,FBSJ,LMDM,FWSJ FROM SFJC.SFJC_WZ_XXNR WHERE FWSJ >DATE_ADD(now(), INTERVAL -11 DAY) and xxzt=8) A ORDER BY FWCS,FWSJ DESC limit ',@beginRecordNum,',',paginalLinage);
elseif lmdm='19' then
set @countSql = concat('select count(1) recNum from (select A.BT, B.FILEPATH,NR,A.CJSJ,1 LX from SFJC.SFJC_WZ_TPXW A, SFJC.SFJC_WZ_TP_PATH B where A.ID=B.TPGLID and A.FBSJ IS NOT NULL and A.xxzt=8 AND A.LMDM=',lmdm,' group by A.ID,A.BT union select BT,'''' FILEPATH,NR,CJSJ, 0 LX from SFJC.SFJC_WZ_XXNR where LMDM=',lmdm,' and FBSJ IS NOT NULL and xxzt=8) a');
set @selectSql = concat('select ID,RID,BT,FILEPATH,NR,FBSJ,datediff(now(),FBSJ) FBTS,LX,LMDM,XXLX,LYZ,FWCS,(select count(1) from SFJC.SFJC_WZ_LTLY A where A.XXID=RID and A.XXLX=XXLX) HFS,(select concat(A.LYRXM,''#=#'',date(A.LYSJ)) from SFJC.SFJC_WZ_LTLY A where A.XXID=RID and A.XXLX=XXLX order by LYSJ DESC limit 1) ZHFB from (select concat(''sp='',A.ID) ID,A.BT, B.FILEPATH,NR,A.FBSJ,1 LX,A.LMDM,A.ID RID,"tp" XXLX,LYZ,FWCS from SFJC.SFJC_WZ_TPXW A, SFJC.SFJC_WZ_TP_PATH B where A.ID=B.TPGLID and A.FBSJ IS NOT NULL and A.xxzt=8 AND A.LMDM=',lmdm,' group by A.ID,A.BT union select concat(''nsp='',ID) ID,BT,'''' FILEPATH,NR,FBSJ, 0 LX,LMDM,ID RID,"xx" XXLX,LYZ,FWCS from SFJC.SFJC_WZ_XXNR where LMDM=',lmdm,' and FBSJ IS NOT NULL and xxzt=8) a ORDER BY FBSJ DESC limit ',@beginRecordNum,',',paginalLinage);
else
set @countSql = concat('select count(1) recNum from (select A.BT, B.FILEPATH,NR,A.CJSJ,1 LX from SFJC.SFJC_WZ_TPXW A, SFJC.SFJC_WZ_TP_PATH B where A.ID=B.TPGLID and A.FBSJ IS NOT NULL and A.xxzt=8 AND A.LMDM=',lmdm,' group by A.ID,A.BT union select BT,'''' FILEPATH,NR,CJSJ, 0 LX from SFJC.SFJC_WZ_XXNR where LMDM=',lmdm,' and FBSJ IS NOT NULL and xxzt=8) a');
set @selectSql = concat('select ID,BT,FILEPATH,NR,FBSJ,datediff(now(),FBSJ) FBTS,LX,LMDM from (select concat(''sp='',A.ID) ID,A.BT, B.FILEPATH,NR,A.FBSJ,1 LX,A.LMDM from SFJC.SFJC_WZ_TPXW A, SFJC.SFJC_WZ_TP_PATH B where A.ID=B.TPGLID and A.FBSJ IS NOT NULL and A.xxzt=8 AND A.LMDM=',lmdm,' group by A.ID,A.BT union select concat(''nsp='',ID) ID,BT,'''' FILEPATH,NR,FBSJ, 0 LX,LMDM from SFJC.SFJC_WZ_XXNR where LMDM=',lmdm,' and FBSJ IS NOT NULL and xxzt=8) a ORDER BY FBSJ DESC limit
',@beginRecordNum,',',paginalLinage);
end if;
prepare countStmt from @countSql;
prepare selectStmt from @selectSql;
execute countStmt;
execute selectStmt;
end
//修改
知识点整理总结:
1.select CONCAT('bh',YHBH) AS YHBH,YHXM from sfjc_yw_ryxx where FYDM='1300B00' AND BZLX != '8'
AND LKYY IS null and yhbh NOT IN (select yhbh from sfjc_jl_djlxr) ORDER BY NBPXH,cast(ZWMC as int)
concat连接字符串,
IS NULL/IS NOT NULL,
cast(expression AS data_type... int/decimal),
如SELECT CAST('12' AS int)但是cast()和convert()都不能执行四舍五入或者截取操作;
SELECT CAST('12.50' AS decimal(9,2)),显示为12.50
2.SELECT * FROM SFJC.SFJC_YW_RYXX A left join sfjc.sfjc_xt_fy B
on A.FYDM=B.FYDM LEFT JOIN sfjc.sfjc_v_wz_jxjb C on A.FYDM=C.FYDM AND a.yhbh=C.yhbh WHERE YHXM ="dddd"
表连接:
tableA A left join tableB B on A.xx = B.xx(left join ... on ...)
3.ALTER table scfz_xewp add BGR varchar(255) after KYR(改变表结构)
4.INSERT INTO scfz_clky (CLBH, AH, LRYH, LRSJ, WJMC)
VALUES ('CLKY-1510-00001', '(2015)案件', '4', now(), '')
5.drop trigger sfjc.sfjc_yw_ryxx_before_update;删除触发器
6.创建触发器
--/
CREATE DEFINER=`sfjc`@`%` TRIGGER `sfjc`.`sfjc_yw_ryxx_before_update`
BEFORE UPDATE ON
sfjc.sfjc_yw_ryxx
FOR EACH ROW begin
set new.xgsj=now();
if new.LKYY is not null then
update sfjc.sfjc_xt_user set sfqy=0 where yhbh=new.yhbh;
end if;
if new.LKYY is null then
update sfjc.sfjc_xt_user set sfqy=1 where yhbh=new.yhbh;
end if;
end
/
7.存储过程的创建和使用
call web_list_proc('19',1,20,'')
java中调用时,(程序中使用)
cStm = con.prepareCall("{call web_list_pf_proc('" + lmdm + "'," + curPage + "," + perPage
+ ",'"+aSearchKey+"','" + selectTimeWhere +"','" + sortTime + "')}");
数据库中创建存储过程:
CREATE DEFINER=`sfjc`@`%` PROCEDURE `sfjc`.`web_list_proc`(in lmdm varchar(10), in showPageNum int, in paginalLinage int, in keyWords varchar(255))
begin
declare countStmt varchar(200);
declare selectStmt varchar(300);
declare beginRecordNum int;
set @beginRecordNum=(showPageNum-1)*paginalLinage;
if lmdm='search' then
set @countSql = concat('select count(1) recNum from (select ID,BT FROM SFJC.SFJC_WZ_TPXW WHERE ',keyWords,' and xxzt=8 union select ID,BT FROM SFJC.SFJC_WZ_XXNR WHERE ',keyWords,' and xxzt=8) A ');
set @selectSql = concat('select ID,BT,FWCS,FBSJ,datediff(now(),FBSJ) FBTS,LMDM from (select concat(''sp='',ID) ID,BT,FWCS,FBSJ,LMDM FROM SFJC.SFJC_WZ_TPXW WHERE ',keyWords,' and xxzt=8 union select concat(''nsp='',ID) ID,BT,FWCS,FBSJ,LMDM FROM SFJC.SFJC_WZ_XXNR WHERE ',keyWords,' and xxzt=8) A ORDER BY FWCS DESC limit ',@beginRecordNum,',',paginalLinage);
elseif lmdm='0' then
set @countSql = concat('select count(1) recNum from (select ID,BT FROM SFJC.SFJC_WZ_TPXW WHERE FWSJ >DATE_ADD(now(), INTERVAL -11 DAY) and xxzt=8 union select ID,BT FROM SFJC.SFJC_WZ_XXNR WHERE FWSJ >DATE_ADD(now(), INTERVAL -11 DAY) and xxzt=8) A ');
set @selectSql = concat('select ID,BT,FWCS,FBSJ,datediff(now(),FBSJ) FBTS,LMDM,FWSJ from (select concat(''sp='',ID) ID,BT,FWCS,FBSJ,LMDM,FWSJ FROM SFJC.SFJC_WZ_TPXW WHERE FWSJ >DATE_ADD(now(), INTERVAL -11 DAY) and xxzt=8 union select concat(''nsp='',ID) ID,BT,FWCS,FBSJ,LMDM,FWSJ FROM SFJC.SFJC_WZ_XXNR WHERE FWSJ >DATE_ADD(now(), INTERVAL -11 DAY) and xxzt=8) A ORDER BY FWCS,FWSJ DESC limit ',@beginRecordNum,',',paginalLinage);
elseif lmdm='19' then
set @countSql = concat('select count(1) recNum from (select A.BT, B.FILEPATH,NR,A.CJSJ,1 LX from SFJC.SFJC_WZ_TPXW A, SFJC.SFJC_WZ_TP_PATH B where A.ID=B.TPGLID and A.FBSJ IS NOT NULL and A.xxzt=8 AND A.LMDM=',lmdm,' group by A.ID,A.BT union select BT,'''' FILEPATH,NR,CJSJ, 0 LX from SFJC.SFJC_WZ_XXNR where LMDM=',lmdm,' and FBSJ IS NOT NULL and xxzt=8) a');
set @selectSql = concat('select ID,RID,BT,FILEPATH,NR,FBSJ,datediff(now(),FBSJ) FBTS,LX,LMDM,XXLX,LYZ,FWCS,(select count(1) from SFJC.SFJC_WZ_LTLY A where A.XXID=RID and A.XXLX=XXLX) HFS,(select concat(A.LYRXM,''#=#'',date(A.LYSJ)) from SFJC.SFJC_WZ_LTLY A where A.XXID=RID and A.XXLX=XXLX order by LYSJ DESC limit 1) ZHFB from (select concat(''sp='',A.ID) ID,A.BT, B.FILEPATH,NR,A.FBSJ,1 LX,A.LMDM,A.ID RID,"tp" XXLX,LYZ,FWCS from SFJC.SFJC_WZ_TPXW A, SFJC.SFJC_WZ_TP_PATH B where A.ID=B.TPGLID and A.FBSJ IS NOT NULL and A.xxzt=8 AND A.LMDM=',lmdm,' group by A.ID,A.BT union select concat(''nsp='',ID) ID,BT,'''' FILEPATH,NR,FBSJ, 0 LX,LMDM,ID RID,"xx" XXLX,LYZ,FWCS from SFJC.SFJC_WZ_XXNR where LMDM=',lmdm,' and FBSJ IS NOT NULL and xxzt=8) a ORDER BY FBSJ DESC limit ',@beginRecordNum,',',paginalLinage);
else
set @countSql = concat('select count(1) recNum from (select A.BT, B.FILEPATH,NR,A.CJSJ,1 LX from SFJC.SFJC_WZ_TPXW A, SFJC.SFJC_WZ_TP_PATH B where A.ID=B.TPGLID and A.FBSJ IS NOT NULL and A.xxzt=8 AND A.LMDM=',lmdm,' group by A.ID,A.BT union select BT,'''' FILEPATH,NR,CJSJ, 0 LX from SFJC.SFJC_WZ_XXNR where LMDM=',lmdm,' and FBSJ IS NOT NULL and xxzt=8) a');
set @selectSql = concat('select ID,BT,FILEPATH,NR,FBSJ,datediff(now(),FBSJ) FBTS,LX,LMDM from (select concat(''sp='',A.ID) ID,A.BT, B.FILEPATH,NR,A.FBSJ,1 LX,A.LMDM from SFJC.SFJC_WZ_TPXW A, SFJC.SFJC_WZ_TP_PATH B where A.ID=B.TPGLID and A.FBSJ IS NOT NULL and A.xxzt=8 AND A.LMDM=',lmdm,' group by A.ID,A.BT union select concat(''nsp='',ID) ID,BT,'''' FILEPATH,NR,FBSJ, 0 LX,LMDM from SFJC.SFJC_WZ_XXNR where LMDM=',lmdm,' and FBSJ IS NOT NULL and xxzt=8) a ORDER BY FBSJ DESC limit
',@beginRecordNum,',',paginalLinage);
end if;
prepare countStmt from @countSql;
prepare selectStmt from @selectSql;
execute countStmt;
execute selectStmt;
end
8.union & union all (其中union会去除重复部分,union all则不会)
select tn,num from t1 union (all) select tn,num from t2
9.select (CASE B.SFQY WHEN 1 THEN '启用' ELSE '未启用' END) SFQY from xxx
10.ALTER TABLE bghc_dept ADD COLUMN SFJY int NOT NULL COMMENT '是否禁用' AFTER BMBH (MySQL)
11.CREATE TABLE 创建表
bghc_splcmx
(
ID VARCHAR(20) NOT NULL,
LCJL VARCHAR(200) NOT NULL COMMENT '流程记录',
SFQY INT NOT NULL COMMENT '是否启用',
SCSJ DATETIME,
XGSJ DATETIME,
PRIMARY KEY (ID)
)
ENGINE=InnoDB DEFAULT CHARSET=gbk COMMENT='审批流程明细';
相关推荐
本资料包“MySQL语句整理”显然是一个关于MySQL查询语言的学习资源,旨在帮助用户掌握和理解如何有效地与MySQL数据库进行交互。下面将详细阐述MySQL的一些核心概念和常用语句。 1. 数据库操作: - `CREATE ...
MySQL 语句大全 MySQL 语句大全是数据库管理系统中最基本也是最重要的一部分。以下是 MySQL 语句大全的知识点总结: 数据库操作 * 显示数据库:使用 `show databases` 语句可以显示当前 MySQL 服务器中的所有...
SQL(Structured Query Language)语句,即结构化查询语言,是操作和检索关系数据库的标准语言。SQL语句一般分为以下几种: DCL(Database Control Language,数据控制语言)语句:主要由GRANT和REVOKE两个关键字...
Mysql中创建各种索引的语句整理 代码 添加PRIMARY KEY(主键索引) 添加UNIQUE(唯一索引) 添加INDEX(普通索引) 添加FULLTEXT(全文索引) 添加多列索引 ) mysql>ALTER TABLE `...
MySQL是一种广泛使用的开源关系型数据库管理系统,其SQL语句是数据操作的核心。在这个主题中,我们将深入探讨MySQL中的一些常用SQL语句,特别是与数据库连接有关的概念,包括左连接、右连接和全连接。 首先,SQL...
### MySQL常用语句详解 ...以上就是从提供的文件中整理出的MySQL常用语句的相关知识点。这些知识点涵盖了MySQL服务器的基础管理、数据库与表的基本操作以及如何授予用户权限等内容,对于初学者来说是非常实用且必要的。
根据提供的文件信息,我们可以整理出一系列关于MySQL的重要知识点与实用语法。MySQL是一种广泛使用的开源关系型数据库管理系统(RDBMS),适用于多种应用场景,包括网站、应用程序和个人项目等。以下是基于给定信息...
根据提供的文件信息,我们可以整理出一系列关于MySQL的重要知识点与操作示例。MySQL是一种广泛使用的开源关系型数据库管理系统,因其高效性、稳定性和易用性而受到开发者们的青睐。以下将详细解析标题和描述中提到的...
MySQL常用SQL语句解析 MySQL是一种关系型数据库管理系统,广泛应用于Web应用程序的开发中。掌握MySQL的常用SQL语句是开发者的必备技能。本文将对常用的MySQL SQL语句进行详细的解析。 1. 查看数据库命令:show ...
3. SQL语言:SQL(结构化查询语言)是操作MySQL的核心工具,包括SELECT(查询数据)、INSERT(插入数据)、UPDATE(更新数据)、DELETE(删除数据)等语句。 4. 关系模型:MySQL基于关系数据库模型,强调数据之间的...
MySQL是一种广泛使用的开源关系型数据库管理系统,由瑞典的MySQL AB公司开发,后来被Sun Microsystems公司收购,...通过上述内容的整理和学习,读者应能对MySQL数据库有一个全面的认识,并能够进行基本的数据库操作。
Mysql 中创建各种索引的语句整理知识 索引是关系数据库管理系统中的一种数据结构,能快速地定位特定的数据,提高查询效率。在 MySQL 中,创建索引的语句有多种,下面将对这些语句进行整理和解释。 一、索引的创建...
本篇文章旨在为初学者提供一份简明扼要的MySQL语句指南,涵盖了数据库管理和操作的基本方面。以下将详细介绍文件中提到的一些关键知识点。 #### 1. 检查MySQL服务状态 ```bash sudo service mysqld status ``` 这...
标题中的“sql跟踪语句整理工具2”表明这是一个专门用于SQL语句跟踪和管理的软件工具,可能是针对数据库开发人员或管理员设计的。这类工具通常能够帮助用户收集、分析和整理在数据库操作过程中产生的SQL语句,以优化...
MySQL优化精华整理文档是针对数据库性能提升的一份详细指南,涵盖了多个关键方面,旨在帮助管理员和开发者提升数据库的运行效率。以下是对各个知识点的详细解释: 1. **我们可以且应该优化什么?** - 优化的目标...
本文将深入介绍MySQL的基本概念、安装过程以及常用的SQL语句,帮助你更好地理解和运用这个强大的数据库系统。 首先,MySQL的核心概念包括数据库(Database)、表(Table)、字段(Field)和记录(Record)。数据库...
MySQL DML(Data Manipulation Language)语句是用于管理和操作数据库中数据的命令,主要包括插入(INSERT)、更新(UPDATE)、删除(DELETE)和查询(SELECT)四种操作。这些语句在数据库开发和管理中占据核心地位...
本人整理了mysql常用函数,仅供小白学习