日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > php >内容正文

php

php 匹配多行,PHP-选择与相关表中的多行匹配的行

發(fā)布時(shí)間:2025/3/20 php 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 匹配多行,PHP-选择与相关表中的多行匹配的行 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

下表較大,但為方便起見已將其縮小

表1 -exercise_rolladex

Exercise_ID | Exercise_Name

---------------------------

1 Pushups

2 Turkish Get Ups

3 Squats

4 Ice Skater

表2-Exercise_planes

Exercise_Plane_ID | Exercise_Plane

----------------------------------

1 Sagittal

2 Frontal

3 Transverse

表3-Exercise_has_planes

Exercise_ID | Exercise_Plane_ID

-------------------------------

1 1

2 1

2 2

2 3

3 1

4 2

4 3

我的問題是:如何構(gòu)造查詢,在其中可以找到每個(gè)具有Exercise_Plane_ID = 1和Exercise_Plane_ID = 2的運(yùn)動(dòng)的Exercise_ID.換句話說,找到既具有矢狀運(yùn)動(dòng)又具有額葉運(yùn)動(dòng)的運(yùn)動(dòng).

正確的查詢

SELECT e.Exercise_Name, p.Exercise_Plane

FROM exercise_rolladex e

INNER JOIN exercise_has_planes h ON h.Exercise_ID=e.Exercise_ID

INNER JOIN exercise_planes p ON p.Exercise_Plane_ID=h.Exercise_Plane_ID

WHERE p.Exercise_Plane_ID IN(2,1)

GROUP BY e.Exercise_ID

HAVING COUNT(DISTINCT h.Exercise_Plane_ID ) >= 2

更新跟進(jìn)問題

那我怎么包括一個(gè)排除項(xiàng)呢?例如,找到使用plane_id 2和3的練習(xí),但排除使用plane_id 1的練習(xí)(正確的結(jié)果是“ Ice Skater”)

我繼續(xù)回答自己的問題:

SELECT e.Exercise_Name, p.Exercise_Plane

FROM exercise_rolladex e

INNER JOIN exercise_has_planes h ON h.Exercise_ID=e.Exercise_ID

INNER JOIN exercise_planes p ON p.Exercise_Plane_ID=h.Exercise_Plane_ID

WHERE p.Exercise_Plane_ID IN(2,3)

AND e.Exercise_ID NOT IN

(SELECT Exercise_ID FROM exercise_has_planes WHERE Exercise_Plane_ID='1')

GROUP BY e.Exercise_ID

HAVING COUNT(DISTINCT h.Exercise_Plane_ID ) >= 2

解決方法:

您可以執(zhí)行以下操作,這將使用給定的輸入ID檢查計(jì)劃ID,并過濾掉每個(gè)練習(xí)組中的計(jì)數(shù)(如果count返回一個(gè)以上),則表示練習(xí)中有飛機(jī),having子句將滿足同時(shí)擁有兩個(gè)飛機(jī)在運(yùn)動(dòng)中

SELECT e.Exercise_Name,

p.Exercise_Plane

FROM exercise_rolladex e

INNER JOIN exercise_has_planes h ON h.Exercise_ID=e.Exercise_ID

INNER JOIN exercise_planes p ON p.Exercise_Plane_ID=h.Exercise_Plane_ID

WHERE p.Exercise_Plane_ID IN(2,1)

GROUP BY e.Exercise_ID

HAVING COUNT(DISTINCT h.Exercise_Plane_ID ) >= 2

標(biāo)簽:inner-join,mysql,php

來(lái)源: https://codeday.me/bug/20191121/2054286.html

總結(jié)

以上是生活随笔為你收集整理的php 匹配多行,PHP-选择与相关表中的多行匹配的行的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。