我现在有四张表,第一张表存储部门,第二张表存储人员信息及部门编号,第三表张存储人员编号及人员卡片号码,第四张存储卡片号码及刷卡记录,我现在想统计第一张表中每个部门下共有多少名员工刷卡。
表间依懒关系:
1,t_b_group: f_groupid f_groupname
2,t_b_consumer:f_consumerID f_groupid
3,t_b_idcard : f_cardno f_consumerid
4,t_d_cardrecord:f_cardno我现在已经查到每个部门有几行了。,但怎么让他做一个统计呢。
如果子查询已经出查这样一个表,你看怎么让他汇总
部门编号
3
1
1
1
1
3
4我现在已经查到对应的部门编号了。但是最后一步怎么让他能汇总表:
部门 数量
3 2
1 4
4 1select f_groupname,count(f_groupname) from t_b_group where f_groupid in (查询子集) group by f_groupname;
帮忙看看这条查询语句对不对?
原语句为:
select f_groupname,sum(int(f_groupid)) from t_b_group where f_groupid in (
select f_groupid from t_b_consumer where f_consumerid in(
select f_consumerid from t_b_idcard where f_cardno in(
select distinct(f_cardno) from t_d_cardrecord ) ))
group by f_groupname; 统计出来只显示部门及编号,不显示部门下有共有多少条记录。请大侠们帮忙解决一下。有精减的SQL语句可以指导一下。谢谢!
表间依懒关系:
1,t_b_group: f_groupid f_groupname
2,t_b_consumer:f_consumerID f_groupid
3,t_b_idcard : f_cardno f_consumerid
4,t_d_cardrecord:f_cardno我现在已经查到每个部门有几行了。,但怎么让他做一个统计呢。
如果子查询已经出查这样一个表,你看怎么让他汇总
部门编号
3
1
1
1
1
3
4我现在已经查到对应的部门编号了。但是最后一步怎么让他能汇总表:
部门 数量
3 2
1 4
4 1select f_groupname,count(f_groupname) from t_b_group where f_groupid in (查询子集) group by f_groupname;
帮忙看看这条查询语句对不对?
原语句为:
select f_groupname,sum(int(f_groupid)) from t_b_group where f_groupid in (
select f_groupid from t_b_consumer where f_consumerid in(
select f_consumerid from t_b_idcard where f_cardno in(
select distinct(f_cardno) from t_d_cardrecord ) ))
group by f_groupname; 统计出来只显示部门及编号,不显示部门下有共有多少条记录。请大侠们帮忙解决一下。有精减的SQL语句可以指导一下。谢谢!
from t_b_group a, t_b_consumer b, t_b_idcard c, t_d_cardrecord d
where a.f_groupid = b.f_groupid and b.f_consumerid = c.f_consumerid
and c.f_cardno = d.f_cardno
group by a.f_groupid, a.f_groupname
from t_b_group a, t_b_consumer b, t_b_idcard c, t_d_cardrecord d
where a.f_groupid = b.f_groupid
and b.f_consumerid = c.f_consumerid
and c.f_cardno = d.f_cardno
group by a.f_groupid, a.f_groupname
a.f_groupid, a.f_groupname, count(distinct d.f_cardno) as cc
from
t_b_group a, t_b_consumer b, t_b_idcard c, t_d_cardrecord d
where
a.f_groupid = b.f_groupid
and
b.f_consumerid = c.f_consumerid
and
c.f_cardno = d.f_cardno
group by
a.f_groupid, a.f_groupname
from t_b_group a, t_b_consumer b, t_b_idcard c, t_d_cardrecord d
where a.f_groupid = b.f_groupid
and b.f_consumerid = c.f_consumerid
and c.f_cardno = d.f_cardno
group by a.f_groupid, a.f_groupname
from t_b_group a, t_b_consumer b, t_b_idcard c, t_d_cardrecord d
where a.f_groupid = b.f_groupid
and b.f_consumerid = c.f_consumerid
and c.f_cardno = d.f_cardno
group by a.f_groupid,a.f_groupname
语法错误(操作符丢失)在查询表达式 ‘count(distinct d.f_cardno)’中。请再次帮忙分析一下。谢谢。我的原句为:
select f_groupname,count(f_groupid) from t_b_group where f_groupid in (
select f_groupid from t_b_consumer where f_consumerid in(
select f_consumerid from t_b_idcard where f_cardno in(
select distinct(f_cardno) from t_d_cardrecord ) ))
group by f_groupname;
from t_b_group a, t_b_consumer b, t_b_idcard c,
(select distinct(f_cardno) from t_d_cardrecord ) d
where a.f_groupid = b.f_groupid
and b.f_consumerid = c.f_consumerid
and c.f_cardno = d.f_cardno
group by a.f_groupid,a.f_groupname