SQL Complex Statement Logging

Source: Internet
Author: User

Check all surgical appointments and the corresponding arrangement, if the scheduled PK is not NULL, then separated by commas (if there are multiple). The SQL statements in MySQL are as follows:

[SQL]View Plaincopyprint?
  1. Select distinct a.pk, A.surgeryname, A.clerkname, A.customername, A.ordertime, B.forecasttime, b.pk surgery_pk,
  2. Case
  3. When c.pk was not null then (select Group_concat (d.pk) from surgery_arrange D where d.su rgery_order_fk=a.pk)
  4. else null end SURGERY_ARRANGE_PK
  5. From (Surgery_order a left join surgery B on a.surgery_fk=b.pk) left join Surgery_arrange C on A.P K=C.SURGERY_ORDER_FK
  6. ORDER by SURGERY_ARRANGE_PK desc, a.ordertime ASC
  7. Limit 0,10

SQL Complex Statement Logging

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.