???20??SQL????????????????????
????????????? ???????[ 2016/11/2 14:24:49 ] ????????????? SQL Server
????????
??????????????????????У?????????????????????????????????????????ó???????????????SQL???????20?????????????????????
??????????и??????????????????????????????Щ?????????
????????SQL???????
????????????????????????????????????????????????????????????????????????????SQL???????????£?
????SELECT * FROM a_table AS a
????LEFT JOIN b_table AS b ON a.id=b.id
????WHERE a.id IN (
????SELECT DISTINCT id FROM a_table
????WHERE user_id IN (100??102??103) GROUP BY user_id HAVING count(id) > 3
????)
???????????
?????????????SQL??????????????????е???????????
????????
??????Σ??????????????????????????????????????е???ID??????????е?“100??102??103”???????????????????????????“count(id) > 3”????????????????????????????????ID??
????????????
????????????a_table??????????20W????b_table?????????2000W????????????£???????????????????????????????????????????
????????????????????
?????????????????? ????????
?????????????????? ?????? ????????
????????λ
????????SQL????????????????????????????????????????????????????????????????????黷?????????
???????????
??????????????????????ID???????????????????
????SELECT * FROM a_table AS a
????LEFT JOIN b_table AS b ON a.id=b.id
????WHERE user_id IN (100)
?????????????????????????????????????????????
?????????????
?????????λ????????????????????????????????????????????????????????????????????????????
????????????????????????????????DB?????????????????????????
??????μ?????????20???????????????????
?????????????????????????У???????????????????????????
????1??????????ID??????У????????????????????????ID???磺1??2??3??4?? … ?? 999
????2????????????????ID??????滻???????SQL???
????3????У???????????????150 ms
????Well Done! ???????????
???????????
????????????????????????λ?????????????????????????????????????????????????????????????ɡ?
???????????????????
?????????????SQL??????????????????????????????????????????????????????ЩSQL?????
???????b_table??a_table?????????? b_table ????? a_table ??????????????1???????????????????????????????a_table ????? b_table ????????????100????
??????????????????????????
??????? ????? С?????????С?? ????? ???????
???????????Щ???????????????????????????????????????????????????????????????????????????????????????????????????
???????
?????????????????????????
????????????????о????????°??·???????????????????????????????????鼮????????ε???????????????SQL???????N?β????????????λ??QA????????????????M*N??????
??????Σ?????????????????????????????????????????y???Щ????????MySQL??????????????Ч?????DB??????????????????????Щ????ɡ?
???????????????????????????????MC?????????
?????????????????Щ????????????е???????????????????????????????????????????????????????????????????????С?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11