SELECT a.Name,
a.id,
a.Type,
a.date,
COUNT(b.pac),
a.ConName
FROM TableA a
JOIN TableB b ON a.Taskgenid = b.Taskgenid
AND a.formgenid = b.formgenid
JOIN TableC c ON A.id = c.ID
JOIN TableD d ON D.Typeid = c.Typeid
WHERE a.date BETWEEN @Begindate AND @Enddate
AND a.type IN (1, 2, 3)
GROUP BY a.Name,
a.id,
a.Type,
a.date,
a.ConName
I doesnt want to group the columns a.id,a.type,a.date,a.conname. If i remove those columns it showing error that a.id, a.type,a.date,a.conname is not group by or aggregate.
I want only Count(b.pac)
Loading


Hemant SrivastavaRank #581 · 4.2K reputationPosted Jul 16, 2013, 7:16 AM EDT
Because I ran almost same query and got the result as below:
SELECT
COUNT(LOCATION.LOC_ID_NR) AS COUNT_OF_LOC_IDs
FROM [TADDRS] AS ADDRESS
INNER JOIN TLOCATN AS LOCATION ON LOCATION.AD_SYS_NR = ADDRESS.AD_SYS_NR
WHERE ADDRESS.CNY_CD = 'US'
GROUP BY ADDRESS.AD_POL_DIV_2_NA, ADDRESS.AD_POL_DIV_2_NA, ADDRESS.AD_PSL_1_CD, ADDRESS.CNY_CD
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 16, 2013, 7:49 AM EDT
If you don't require those in output column then you can remove from select list otherwise you have to use join for same query
Regards,
Iftikar
Santosh Kumar127 reputationPosted Jul 16, 2013, 10:23 PM EDT
Vishwas Kadamannaya111 reputationPosted Jul 16, 2013, 10:30 PM EDT
First choose what u need in SELECT statement and then group only that columns,
SELECT a.Name,
COUNT(b.pac)
FROM TableA a
JOIN TableB b ON a.Taskgenid = b.Taskgenid
AND a.formgenid = b.formgenid
JOIN TableC c ON A.id = c.ID
JOIN TableD d ON D.Typeid = c.Typeid
WHERE a.date BETWEEN @Begindate AND @Enddate
AND a.type IN (1, 2, 3)
GROUP BY a.Name
Santosh Kumar127 reputationPosted Jul 16, 2013, 10:39 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 16, 2013, 10:54 PM EDT
Regards,
Iftikar
Ravi ShekharRank #673 · 3.6K reputationPosted Jul 17, 2013, 2:01 AM EDT