Help on Count function [Resolved]

Posted by Vijayar under C# on 6/14/2011 | Points: 10 | Views : 1157 | Status : [Member] | Replies : 5
Hi
I am having 2 tables with different columns .

Employee with columns eid,ename,sal and

product with columns pid,pname,pdesc .My problem is i want to get the count of eid and pid as a single column without common column in tables.Is this possible if Possible help me out
ex: Count of eid=4 and count of pid=9

select Count(eid) from Employee=4
select Count(pid) from product=9

o/p
count of eid and pid=13 is my desired result

vijaya


Responses

Posted by: Ndebata on: 6/15/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Select *,X.EmployeeCount+X.ProductCount As TotalCount from (
Select COUNT(1) EmployeeCount,
(Select COUNT(1) from Product Where PID=3) ProductCount
from Employee Where EID=3) as X

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 6/15/2011 [Member] Starter | Points: 25

Up
0
Down
try this

create procedure ca
as
begin
declare @x int
declare @y int
declare @z int

set @x=(select count(pid) from product)
set @y=(select count(eid) from temp)
set @z=@x+@y
print @z
end

Thanks&Regards
LakshmiNarayana Nalluri.

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 6/15/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
Thanks for ur answer,But i want the total for a particular id
i want to see for the count where eid=3 or/and pid=3

if total eid==80 and for eid=3 the count is 7
if total pid=50 and for pid=3 the count is 10
output should be 17


vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 6/15/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
Thanks for ur reply.It worked well


vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 6/16/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
i am grouping the total employees based on dept id which is present in both tables.Now i want the department name of the employee which is present in department table and the difference of employees(department-total)
how to do this please help me
dept id-10-employees 100
Total employees 100

I am writing query like this

select y.total as count1,deptid from
(Select sum(X.empid) As total,X.DeptId
from (
select r.deptid,COUNT(*) empid
from employee r Where empid=17 group by r.deptid
union all
select deptId, COUNT(*) empid from product where
pid=17 group by deptid
) as X group by X.DeptId) as y

How to extend to get deptname and difference

difference=90,dept name Help me in this issue .It's urgent


vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response