简体   繁体   中英

unable to get exact results for select query with join

this is my query

 select count(fp.kat),fs.cid,fcc.cid
 from tbl1 fs
left join tbl2 fp  on fs.cid=fp.cid
left join tbl3 fcc on fcc.cid=fp.kat
group by fcc.cid,fs.cid

which output

count(fp.kat)       cid         cid

 3                1          3


 2                2          3

1                 3           4

2                 4           4

but i want the ourput as

   count       cid
     2            3

     2             4

i dont know whats the issue please let me know

select count(*), x
from
(
    select count(fp.kat),fs.cid,fcc.cid as x
    from tbl1 fs
    left join tbl2 fp  on fs.cid=fp.cid
    left join tbl3 fcc on fcc.cid=fp.kat
    group by fcc.cid,fs.cid
) y
group by x

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM