Home Database Mysql Tutorial MySQL 写SQL吃饭中被call起,帮她解决一个SQL的过程_MySQL

MySQL 写SQL吃饭中被call起,帮她解决一个SQL的过程_MySQL

Jun 01, 2016 pm 01:26 PM
email University

bitsCN.com

正吃饭中被大学同学call起,帮他同事解决一个复杂的SQL问题

 

1 SHE第一封email:

select distinct Test.Name,Test.ID,Plan_Device.ID from Test,Plan_Device where Test.ID in(select TestID from TestResult where (StatusID=1 || StatusID=2)

and PlanResultID=(select ID from PlanResultwhere Sessionid='tangzm_ASBSH2_20131204_10371' and PlanID=(select ID fromTestPlan where Name='MEG_DS3_RRA_FT_MCM3_003')))

and Test.TestPlanID=Plan_Device.TestPlanID

 

select Test.Name,Test.IDfrom Test,AssociateTest where (AssociateTest.TestID=69721or AssociateTest.AssoccaseID=69721) and

(Test.ID=AssociateTest.AssoccaseID orTest.ID=AssociateTest.TestID);

 

现在有这样两个查询,我需要的字段是第二句中的Test.Name,Test.ID和第一句中的Plan_Device.ID

第二句中的69721应该是第一句中查询结果的Test.ID

请问这个语句应该怎么写呢?

 

 

2 ME第二封email:

SELECT DISTINCTTest.Name,Test.ID,Plan_Device.ID

FROMTest,Plan_Device,AssociateTestWHERE Test.ID IN (SELECT TestID FROM TestResult WHERE (StatusID=1 ||StatusID=2)

AND PlanResultID=(

SELECT ID FROM PlanResult WHERE Sessionid='tangzm_ASBSH2_20131204_10371' ANDPlanID=(SELECT ID FROM TestPlan WHERE NAME='MEG_DS3_RRA_FT_MCM3_003')))

ANDTest.TestPlanID=Plan_Device.TestPlanID

and (AssociateTest.TestID=Test.ID ORAssociateTest.AssoccaseID=Test.ID)

AND (Test.ID=AssociateTest.AssoccaseID ORTest.ID=AssociateTest.TestID);

 

黄色部分是我添加进去的,你看看是否可以运行得到你要的结果。

[备注]:我以为是简单的取值,直接把第三张表关联起来把判断条件加上不就行了吗?

 

3 SHE第三封email:

结果显示和第一句查询的结果相同

 

select Test.Name,Test.IDfrom Test,AssociateTest where (AssociateTest.TestID=69721or AssociateTest.AssoccaseID=69721) and

(Test.ID=AssociateTest.AssoccaseID orTest.ID=AssociateTest.TestID);

应该显示两行结果,一行是AssociateTest.TestID=69721查询出来的,另一行是AssociateTest.AssoccaseID=69721查询出来的

 

[备注] 看到她的回复,再仔细看看她第一封email的描述,我知道了她的意思,不仅仅是简单关联,是要把2个结果集归纳到一起,再取出值,换思路吧。

 

 

4 ME第四封email:

想了想,要使用单独集合了,写了sql,发email给她,你试下下面这个:

 

SELECTTest.Name,Test.ID,TP.Plan_Device_IDFROM Test,AssociateTest,(

SELECTDISTINCT Test.Name,Test.ID,Plan_Device.ID Plan_Device_ID

FROM Test,Plan_DeviceWHERE Test.ID IN (SELECT TestID FROM TestResult WHERE (StatusID=1 ||StatusID=2)

ANDPlanResultID=(

SELECT ID FROM PlanResult WHERE Sessionid='tangzm_ASBSH2_20131204_10371' ANDPlanID=(SELECT ID FROM TestPlan WHERE NAME='MEG_DS3_RRA_FT_MCM3_003')))

ANDTest.TestPlanID=Plan_Device.TestPlanID

)TP

WHERE(AssociateTest.TestID=TP.IDOR AssociateTest.AssoccaseID=TP.ID)AND (Test.ID=AssociateTest.AssoccaseID OR Test.ID=AssociateTest.TestID);

 

 

5SHE第五封email:

 

这个可以用, 谢谢!

 

OK,搞定了。

bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
How to use email, smtplib, poplib, imaplib modules to send and receive emails in Python How to use email, smtplib, poplib, imaplib modules to send and receive emails in Python May 16, 2023 pm 11:44 PM

The journey of an email is: MUA: MailUserAgent - Mail User Agent. (i.e. email software similar to Outlook) MTA: MailTransferAgent - Mail transfer agent, which is those email service providers, such as NetEase, Sina, etc. MDA: MailDeliveryAgent - Mail delivery agent. A server of the Email service provider sender->MUA->MTA->MTA->if

Which universities in China use Canvas as a teaching platform? Which universities in China use Canvas as a teaching platform? Jan 17, 2024 am 09:47 AM

With the rapid development and popularization of Internet technology, the education industry is constantly undergoing changes and innovations. In university teaching, traditional paper textbooks and face-to-face courses can no longer meet students' learning needs. Therefore, electronic teaching platforms emerged as the times require and became a new choice for university teaching. Many universities in China have begun to use Canvas as a teaching platform. Canvas is a teaching management system (Learning Management System, referred to as LMS) from the United States, developed by I

Which university has the best artificial intelligence major? The answer is revealed, this article analyzes it thoroughly Which university has the best artificial intelligence major? The answer is revealed, this article analyzes it thoroughly Nov 01, 2023 pm 05:53 PM

I saw a netizen asking a question on a Q&A platform: Which Chinese university has a better artificial intelligence major? The artificial intelligence majors of these 9 universities were rated A+. With the development and progress of science and technology, artificial intelligence has become inseparable from our work and life. Healthy sports bracelets, scanning QR codes when purchasing things, face recognition, voice recognition, voice assistants, fingerprint recognition, etc., all belong to the category of artificial intelligence, not to mention intelligent robots. The development prospects of artificial intelligence are very good. If heavy industry is a sunset industry, artificial intelligence is a sunrise industry. It is a high-tech industry. With the continuous development of social productivity, big data, cloud computing, Internet of Things and other related technologies will become more and more important. Widely used in our daily life, intelligent development has

Tutorial on how to insert attachments into win10 mailbox Tutorial on how to insert attachments into win10 mailbox Jan 07, 2024 pm 12:14 PM

Many users need to send emails for work in their daily lives, and some even need to attach various plug-in materials for communication. So how to insert attachments? Let’s take a look at the detailed tutorial below. How to insert attachments to win10 mailbox: 1. Open the mailbox 2. Click the "New Mail" icon in the upper left corner 3. Click "Insert" in the upper right corner 4. Click "Attachment" in the upper right corner 5. Select the required "Attachment" 6. Complete

What is the method for springboot hutool to integrate email? What is the method for springboot hutool to integrate email? May 11, 2023 pm 12:55 PM

Content introduction This article introduces two ways to send email files. Springboot integrates email to send files. Springboot uses hutool to integrate email to send files. To send email files, you need to enable popspringboot to integrate email to send files. Import depends on org.springframework.bootspring-boot-starter-mail configuration file spring: mail:default-encoding:utf-8host:smtp.aliyun.comusername:email account password:password send email test

Email in Yii framework: Implementing email sending Email in Yii framework: Implementing email sending Jun 21, 2023 am 08:49 AM

The Yii framework is a high-performance, open source web development framework with efficient routing and modularity mechanisms that is ideal for quickly developing complex web applications. Among them, sending emails is one of the inevitable functions of any application. In the Yii framework, it is very simple to implement email sending, and it also provides many customization options and rich business logic support. 1. Email configuration in the Yii framework In the Yii framework, the configuration file is a very important resource, used to configure the basic information of the application and various groups.

The country's first 10G all-optical campus was born: 800 student dormitories jumped from 100G to 10G The country's first 10G all-optical campus was born: 800 student dormitories jumped from 100G to 10G Jun 08, 2024 am 10:33 AM

According to news on June 6, Hubei Mobile and Huawei completed the country's first all-optical campus dormitory network coverage project based on 50GPON+FTTR technology at the Han Science Garden of Yangtze University in Jingzhou, Hubei. It is understood that this project covers a total of 5 dormitory buildings, and this area used to use Jingzhou Mobile Campus 100M broadband. With the upgrade of campus informatization and digitalization, in order to better meet the needs of students and faculty for ultra-high-speed and stable network experience, the industry's new 50GPON technology + FTTR all-fiber networking solution provided by Jingzhou Mobile is used for network upgrade. , achieving full-fiber 10G access to 800 dormitories. Based on the original campus FTTR network, Jingzhou Mobile upgraded the central office network to 50GPON, through end-to-end F5G-A

Many colleges and universities provide online bed selection functions. Freshmen can choose a suitable dormitory based on their personal preferences and roommate information. Many colleges and universities provide online bed selection functions. Freshmen can choose a suitable dormitory based on their personal preferences and roommate information. Aug 22, 2023 pm 12:49 PM

With the beginning of the new semester, many colleges and universities have provided online self-selected bed services for freshmen. In this way, freshmen can choose a suitable dormitory based on their preferences and roommate information. According to China Youth Daily, the 2023 freshmen of the University of Electronic Science and Technology of China can choose their own rooms online and can accurately select the bed number. The room selection area is divided by college classes, and freshmen choose rooms within the college class area. It is worth mentioning that during the room selection process, students can check the information of the roommates in the selected bed, including getting up, napping, sleeping late, sleep quality, etc. In addition, in order to meet the needs of students over 1.9 meters tall, the dormitory area also provides extra-long beds. Zhuhai University of Science and Technology launched the online dormitory selection function a few years ago, and this year is no exception. Before choosing a dormitory, new

See all articles