SQL简介

1.SQL语言包括:资料定义语言(DDL)和资料操作语言(DML);

2.DDL

3.DML

(1)SELECT

SELECT * FROM CXLAT.DTATH005 WHERE POL_NUM = '07AX00087544' AND CASE_TYPE = '01'
(2)INSERT

INSERT INTO CXLAL.DTALB077(CODE,SER_NO,SQL_KEY,RANGE,RESULT,PRC_DT,FLAG)
VALUES('LQRO00011',1,'com.cathay.al.b1.check.LQRO00011','[0,0]',NULL,NULL);

如果插入的数值的顺序与数据库中栏位顺序相同,可以直接写成

INSERT INTO CXLAL.DTALB077 VALUES('LQRO00011',1,'com.cathay.al.b1.check.LQRO00011','[0,0]',NULL,NULL);

(3)DELETE

DELETE FROM CXLAT.DTATH005 WHERE POL_NUM = '07AX00087544' AND CASE_TYPE = '01'

(4)UPDATE

UPDATE CXLAL.DTALB077 SET RESULT = 0.00,PRC_DT = '2017-08-10',FLAG = '0' WHERE CODE = 'LQRO00011'
注意:

1.更新多个字段时用,隔开,而不是and;

2.UPDATE的级联更新

UPDATE A SET (A1,A2,A3) = (SELECT B1,B2,B3 FROM B WHERE A.ID=B.ID) WHERE ID IN(SELECT B.ID FROM B WHERE A.ID=B.ID)

只能用这种子查询,不能用关联查询

(5)常用举例

1.with的用法

with aa as
(select count(*) a  from cxlal.DTALB044_LLRECEIPT_B
 where Sex ='0' or Sex ='9'),
bb as
(select count(*) b from CXLAL.DTALB044_LLRECEIPT_B)
select aa.a*1.00/bb.b from aa,bb
2.INSERT SELECT

INSERT INTO A

SELECT * FROM B WHERE ID_NO = 'CUST_NO'

注意:B表的栏位必须与A表的一一对应,如果不对应,则不能用*;而要将正确的栏位顺序查询出来

INSERT INTO A

SELECT ID_NO,NAME,GENDER FROM B WHERE ID_NO = 'CUST_NO'




你可能感兴趣的:(数据库)