I have the following table:
CodeName cnt cnt
CodeNAmeA 1111 2222
CodeNAmeB 3333 4444
CodeNAmeC 5555 6666
This table is the result of the following query:
(select a.CodeName, a.cnt, b.cnt from
(select tableA.CodeName, count(*) cnt
from aaaa..AAAA tableA inner join bbbb..BBBB tableB
on tableA.CodeName = tableB.CodeName
where XXXXXXX
group by tableA.CodeName) a
JOIN
(select tableA.CodeName, count(*) cnt
from aaaa..AAAA tableA inner join bbbb..BBBB tableB
on tableA.CodeName = tableB.CodeName
where XXXXXXX
group by tableA.CodeName,tableA.INAMALOCK) b
ON a.CodeName = b.CodeName)
I have another table like this:
CodeName RealName
CodeNAmeA RealNameA
CodeNAmeB RealNameB
CodeNAmeC RealNAmeC
This table is the result of a simple select query
select CodeName
from TableCodeReal
What I want to do is show the folowing:
RealName cnt cnt
RealNameA 1111 2222
RealNameB 3333 4444
RealNameC 5555 6666
The problem comes that I don’t have the real name in the aaaa..AAAA or bbbb..BBBB, how do I get the result of the first query and do the replacement?. Thank very much, I get very confused about how to integrate the second table in the first query.
I believe this is what you require.
Make your main query a sub query and join onto your second table on the
CodeNamevalue. Then select theRealNamefrom your second table, along with yourcntvalues (which I have aliased asacntandbcnt).