在2个表中选择少于2个订单?[连接表] [英] Select less than 2 orders in 2 tables?[join tables]

查看:83
本文介绍了在2个表中选择少于2个订单?[连接表]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有2张桌子,

1. tbl_emp1,(主键是 Id

2. tbl_emp2(外键是 emp1id )。

Hi,

I have 2 tables,
1. tbl_emp1,(primary key is Id)
2. tbl_emp2(foreign key is emp1id).

select count(emp1id) from tbl_emp2 group by emp1id





以上查询返回,

1

2

3

7

2

3

2



我只想要3,7,3。不小于3.



Above query returns,
1
2
3
7
2
3
2

I want only 3,7,3. Not less than 3.

推荐答案

由Maciej Los提示并且OP已经感谢我,我将发布此作为解决方案。

对于你的第一个查询,我认为你应该有
Prompted by Maciej Los and as the OP has thanked me I'll post this as the solution.
For your first query I think you should have
select emp1id, count(emp1id) from tbl_emp2 groupy by emp1id having count(*) > 2


这篇关于在2个表中选择少于2个订单?[连接表]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆