完美解析SQL只需要簡單的十個步驟

select?A.x?+?A.y?AS?z  FROM?A  WHERE?z?=?10?--?z?在此處不可用,因?yàn)镾ELECT是最后執(zhí)行的語句!
SELECT?A.x?+?A.y?AS?z  FROM?AWHERE?(A.x?+?A.y)?=?10

?::=????

??|? ??|?

FROM?a,?b,?c,?d,?e,?f,?g,?h  WHERE?a.a1?=?b.bxAND?a.a2?=?c.c1AND?d.d1?=?b.bc  --?etc...
--?This?table?reference?contains?authors?and?their?books.  --?There?is?one?record?for?each?book?and?its?author.  --?authors?without?books?are?NOT?included  author?JOIN?book?ON?author.id?=?book.author_id    --?This?table?reference?contains?authors?and?their?books  --?There?is?one?record?for?each?book?and?its?author.  --?...?OR?there?is?an?"empty"?record?for?authors?without?books  --?("empty"?meaning?that?all?book?columns?are?NULL)  author?LEFT?OUTER?JOIN?book?ON?author.id?=?book.author_id
--?Using?IN  FROM?author  WHERE?author.id?IN?(SELECT?book.author_id?FROM?book)    --?Using?EXISTS  FROM?author  WHERE?EXISTS?(SELECT?1?FROM?book?WHERE?book.author_id?=?author.id)
--?Find?only?those?authors?who?also?have?books  SELECT?DISTINCT?first_name,?last_name  FROM?author  JOIN?book?ON?author.id?=?book.author_id
--?Using?IN  FROM?author  WHERE?author.id?NOT?IN?(SELECT?book.author_id?FROM?book)    --?Using?EXISTS  FROM?author  WHERE?NOT?EXISTS?(SELECT?1?FROM?book?WHERE?book.author_id?=?author.id)
author?CROSS?JOIN?book
--?A?derived?table  FROM?(SELECT?*?FROM?author)
--?A?derived?table?with?an?aliasFROM?(SELECT?*?FROM?author)?a
--?Get?authors'?first?and?last?names,?and?their?age?in?days  SELECT?first_name,?last_name,?age  FROM?(  ??SELECT?first_name,?last_name,?current_date?-?date_of_birth?age  ??FROM?author  )  --?If?the?age?is?greater?than?10000?days  WHERE?age?>?10000
WITH?a?AS?(  ??SELECT?first_name,?last_name,?current_date?-?date_of_birth?age  ??FROM?author  )  SELECT?*  FROM?a  WHERE?age?>?10000
SELECT?A.x,?A.y,?SUM(A.z)FROM?AGROUP?BY?A.x,?A.y

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊12 分享