❶ 请解释一下以下sql 语句.
SELECT
INVMA.MA002ASMA002,--这里取别名就不需要说明了吧?下同
INVMA.MA003ASMA003,
INVMA.MA004ASMA004,
MB001,MB002,MB003,MB004,MB072,MB090,MB057,MB058,MB059,MB060,MD003,MD004,
A.MA003陪段液ASMA003C,
MF004,MF005,
CASEWHENINVMA.MA001='1'THENINVMB.MB005--当INVMA.MA001='1'时取INVMB.MB005的值
芦物WHENINVMA.MA001='2'THENINVMB.MB006--当INVMA.MA001='2'时取INVMB.MB006的值
WHENINVMA.MA001='3'THENINVMB.MB007--当INVMA.MA001='3'时取INVMB.MB007的值
WHENINVMA.MA001='4'THENINVMB.MB008ENDCATEGORY,--当INVMA.MA001='4'时取INVMB.MB008的值
FLOOR(ABS(ISNULL(LC004,0)))--ISNULL(LC004,0)当LC004为null时赋值0,abs()取绝对值,FLOOR向下去整数floor(2.9)=2
*SIGN(ISNULL(LC004,0))--SIGN()符号函数SIGN(X),当x>0是结果为1当x<0结果为-1,当x=0结果为0
+SUM(ISNULL(INVLA.LA005*FLOOR(ABS(INVLA.LA011))*SIGN(INVLA.LA011),0))INVNUMA,
ISNULL(LC004,0)-FLOOR(ABS(ISNULL(LC004,0)))*SIGN(ISNULL(LC004,0))
+SUM(ISNULL(INVLA.LA005*(INVLA.LA011-FLOOR(ABS(INVLA.LA011))*SIGN(INVLA.LA011)),0))INVNUMB,
(ISNULL(LC030,0)+SUM(ISNULL(INVLA.LA021,0)*ISNULL(INVLA.LA005,0)))QUANTYPACK,
(ISNULL(LC005,0)+SUM(ISNULL(INVLA.LA013,0)*ISNULL(INVLA.LA005,0)))INVMONEY,I.MC002ASMC002,C.MC002ASMC002C
FROM
(
selectINVMC.MC001MC001,INVMC.MC002MC002FROMRAYSONDATE....INVMCINVMCONMB001=INVMC.MC001LEFTJOINRAYSONDATE..CMSMCCMSMCONCMSMC.MC001=INVMC.MC002LEFTJOINRAYSONDATE..INVMAASINVMAONMA001='1'ANDMA002=MB005
where1=1and(INVMC.MC002IN('005'))ANDCMSMC.MC004='1'
UNION--合并前后两个查询语句的结果集,并且去掉两燃明者中重复的行
SELECTDISTINCT--去掉查询结果中的重复行
LA001ASMC001,LA009ASMC002
FROMRAYSONDATE..INVLALEFTJOIN--左连接
RAYSONDATE..CMSMCONMC001=LA009--RAYSONDATE数据库的CMSMC表
whereMC018='N'and(LA009IN('005'))ANDMC004='1'
)asI--把括号里的两个查询的结果当成一个虚拟表,并且取名为I
❷ 请解释下这句sql语句是什么意思,谢谢
先说下他的作用吧,他的意思就是stu表里如果没有autohtmlshow=22的数据,就往stu表里插入一条name='libo',autohtmlshow=22的数据,如果有的话则不插入
然后说下每句的意思吧
not exists (select * from stu where autohtmlshow=22)里exists 函数是返回一个bool值,意识就是汪敏如果括号里有值就返回true,如果没有就返回false,not就是取反,意思就是如果这条语句没有值的话执行这条查询语句
limit 1是取第一行的值
至于select 'libo',22 from (select name,autohtmlshow from stu union select 'libo',22) x 我感觉不怎么需要,你完全可以写成
insertintostu(name,autohtmlshow)select'libo',22wherenotexists(select*fromstuwhereautohtmlshow=22)
前面的话是芦哪一条插入语句,这个应困哗枝该不用解释了,希望能够帮到你