SQL query statement resolution encountered in---work of personal work record

Source: Internet
Author: User
Tags select from where

In the work of writing the first query statement of life, although the original based on the change, but still learned a lot of knowledge

Code:

SELECT DISTINCT M.id, (select Z.jianc from MODEL_ZUZJG z where z.id=m.huoz_id) as Huoz, (select MINGC from Model_pinz where                                                                                                   id=m.meiz_id) as Meiz,ifnull ((select Kc.shul from Yw_kuczt KC where kc.meiduo_id=m.id), 0) as Shul, M.duom,ll.longitude,ll.latitude, Ifnull (Sele CT Mb.shouc_beiz from model_tongd_bzxx MB where mb.tongd_id=m.tongd_id and mb.huoz_id=m.huoz_id and mb.meiz_id=m.meiz_id and mb.user_id= ' 1 ') as Shouc_beiz,ifnull ((select Mb.shouc_status from model_tongd_bzxx MB where MB.TONGD_ID=M.TONGD _id and mb.huoz_id=m.huoz_id and mb.meiz_id=m.meiz_id and mb.user_id= ' 1 '), 0) as Shouc_status, m.huoz_id, M.meiz_idfrom mo Del_meidxx m INNER JOIN (select T.ID,T.DAIM,T.TONGDMC from Model_tongd T, (select Daim from Model_jicss where (shangjdm= ' GXTSG ' OR daim= ' GXTSG ') and fenl= ' B ') J where T.suosjcss=j.daim) TD on M.tongd_id=td.id INNER JOIN (select L.duo_id,l. Longitude,l.latitude from MoDEl_meid_lbxx L Group by l.duo_id) ll on M.id=ll.duo_idwhere m.state=1 

Interpretation (Memo):

1. A subquery can be added as a temporary parameter to any stage in the select from where

2.as can temporarily assign a table alias or table name alias to write

3.ifnull ((), ') when the data being found does not exist as NULL, a different value can be assigned

4.distinct to re-fetch once

Other: MODEL_MEIDXX is the primary table, where all the data comes from whatever tables need to be associated with them, and where in the end represents the core query criteria.

SQL query statement resolution encountered in---work of personal work record

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.