本文介绍了如何从数据库查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨伙计 我想获得未满18岁的记录 我有两张桌子家庭,成员 家庭: id name 1 Famliy1 2 Famliy2 3 Famliy3 4 Famliy4 成员: id fid name 年龄 1 1 AAAAA 11 2 1 BBBBB 19 3 1 CCCCC 14 4 2 DDDDD 18 5 2 EEEEEE 29 6 2 FFFFFF 23 7 3 GGGGG 13 8 3 HHHHH 14 9 3 IIIIII 16 10 4 JJJJJJ 22 11 4 KKKKK 24 12 4 LLLLLL 25 I想得到家庭没有18岁以下成员的名字解决方案 尝试: SELECT m.id,m.name,f.name,m.Age FROM 成员m JOIN 族f ON m.fid = f.id 在哪里 m.Age> 17 ok我想在会员表中获取最后三个记录,因为他们没有18岁以下的成员 您的数据不会这样做:FID 2有没有18岁以下的成员。 但是试试这个: SELECT m。 id,m.name,f.name,m.Age FROM 成员m JOIN ( SELECT Fid FROM 成员 GROUP BY Fid HAVING MIN(AGE)> 17 ) j ON j.Fid = m.FID JOIN 家庭f ON m.Fid = f.Id 要获得最后三行,您需要排除18岁以及: SELECT m.id,m.name,f.name,m.Age FROM 成员m JOIN ( SELECT Fid FROM 成员 GROUP BY Fid HAVING MIN(AGE)> 18 )j ON j.Fid = m.FID JOIN 族f ON m.Fid = f.Id 试试这个: SELECT F.id, F.name FROM family As F WHERE 不 存在 ( SELECT 1 FROM 成员作为 M WHERE M.fid = F.id 和 M.Age< 18 ); hi guys I want to get records that haven't Age under 18I have two tables family, membersfamily: id name 1 Famliy1 2 Famliy2 3 Famliy3 4 Famliy4 members: id fid name Age 1 1 AAAAA 11 2 1 BBBBB 19 3 1 CCCCC 14 4 2 DDDDD 18 5 2 EEEEEE 29 6 2 FFFFFF 23 7 3 GGGGG 13 8 3 HHHHH 14 9 3 IIIIII 16 10 4 JJJJJJ 22 11 4 KKKKK 24 12 4 LLLLLL 25 I want to get family name that haven't member under 18 解决方案 Try:SELECT m.id, m.name, f.name, m.AgeFROM Members mJOIN Family f ON m.fid = f.idWHERE m.Age > 17ok I want to get the last three records in members table because they haven't members under 18Your data doesn't do that: FID 2 has no members under 18.But try this:SELECT m.id, m.name, f.name, m.Age FROM Members mJOIN (SELECT Fid FROM Members GROUP BY Fid HAVING MIN(AGE) > 17) jON j.Fid = m.FIDJOIN Family f ON m.Fid = f.IdTo get just the last three rows, you need to exclude 18 year olds as well:SELECT m.id, m.name, f.name, m.Age FROM Members mJOIN (SELECT Fid FROM Members GROUP BY Fid HAVING MIN(AGE) > 18) jON j.Fid = m.FIDJOIN Family f ON m.Fid = f.IdTry this:SELECT F.id, F.nameFROM family As FWHERE Not Exists ( SELECT 1 FROM Members As M WHERE M.fid = F.id And M.Age < 18 ); 这篇关于如何从数据库查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-15 14:29