gpt4 book ai didi

mysql - 返回特定行数满足特定条件的值的查询

转载 作者:行者123 更新时间:2023-11-30 00:56:55 25 4
gpt4 key购买 nike

我正在尝试制作报告,但在设计查询来显示我需要的数据时遇到一些困难。

我有 2 张 table :

+-----------+------------+----------+
+TherapyID + CostumerID + ClinicID +
+-----------+------------+----------+
+ 1 + John + Clinic 1 +
+-----------+------------+----------+
+ 2 + Susan + Clinic 2 +
+-----------+------------+----------+
+ 3 + Mary + Clinic 3 +
+-----------+------------+----------+


+-----------+--------------+-----------+--------+
+TherapyID + TherapyLine + Treatment + Result +
+-----------+--------------+-----------+--------+
+ 1 + 1 + A + Success+
+-----------+--------------+-----------+--------+
+ 1 + 2 + B + Success+
+-----------+--------------+-----------+--------+
+ 1 + 3 + C + Success+
+-----------+--------------+-----------+--------+
+ 2 + 1 + A + Success+
+-----------+--------------+-----------+--------+
+ 2 + 2 + B + Fail +
+-----------+--------------+-----------+--------+
+ 2 + 3 + C + Success+
+-----------+--------------+-----------+--------+
+ 3 + 1 + A + Success+
+-----------+--------------+-----------+--------+
+ 3 + 2 + B + Success+
+-----------+--------------+-----------+--------+
+ 3 + 3 + C + Fail +
+-----------+--------------+-----------+--------+

我需要进行一个查询,仅向我显示已成功接受所有治疗A、B、C的客户或therapyid

查询结果应该是这样的:

+------------+-------------+----------+---------+-----------+---------+
+ TherapyID + TherapyLine + Customer + Clinic + Treatment + Result +
+------------+-------------+----------+---------+-----------+---------+
+ 1 + 1 + John + Clinic 1+ A + Success +
+------------+-------------+----------+---------+-----------+---------+
+ 1 + 2 + John + Clinic 1+ B + Success +
+------------+-------------+----------+---------+-----------+---------+
+ 1 + 3 + John + Clinic 1+ C + Success +
+------------+-------------+----------+---------+-----------+---------+

这是唯一一种所有治疗A、B、C成功的疗法我真的不知道如何查询这个,我到目前为止已经尝试过始终从 TherapyID *2,3* 返回结果,其中结果也是成功。提前感谢您的帮助。

最佳答案

select t1.TherapyID,TherapyLine,t1.CostumerID as Customer,Clinic,Treatment, 
Result from table1 t1,table2 t2 where t1.TherapyID =t2.TherapyID and
t2.result='Success' group by customerID having count(customeID)=3

关于mysql - 返回特定行数满足特定条件的值的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20475516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com