[英]MySQL - SELECT COUNT from two tables
I have these two tables: 我有这两个表:
type 类型
TYPE_ID TYPE
1 Type1
2 Type2
3 Type3
4 Type4
user_type 用户类型
USRTYPE_ID TYPE_ID
1 1
2 1
3 2
4 4
What I need to do is count how many types are there in user_type table. 我需要做的是计算 user_type表中有多少种类型。 For eg
例如
SELECT QUERY
returns: SELECT QUERY
返回:
TYPE QUANTITY
Type1 2
Type2 1
Type4 4
This should work 这应该工作
select count(USRTYPE_ID) as QUANTITY, TYPE
from user_type
inner join type
on user_type.TYPE_ID = type.TYPE_ID
group by TYPE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.