❶ 請解釋一下以下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)
前面的話是蘆哪一條插入語句,這個應困嘩枝該不用解釋了,希望能夠幫到你