what is the difference between group and having
give an example with query and sample output
Answer Posted / soorai ganesh
create table lovepair (boyfrndname varchar(10),girlfrndname
varchar(10))
insert into lovepair values ('BF1','GF1')
insert into lovepair values ('BF1','GF2')
insert into lovepair values ('BF1','GF3')
insert into lovepair values ('BF2','GF1')
insert into lovepair values ('BF2','GF2')
insert into lovepair values ('BF3','GF3')
insert into lovepair values ('BF3','GF3')
insert into lovepair values ('BF3','GF3')
-- Here BF1 have 3 Girl Friends. like the BF2 and BF3 have
2 and 3 Girl Friends Simultaneously.
-- Here is the query for, how many girls friends each boys
have ???? USING group by
SELECT boyfrndname, COUNT (*)
FROM lovepair
GROUP BY boyfrndname
// Here another qry for who have more than 2 girl
friends ?? USING GroupBy and Having .
// Having is used for applying some condition in Aggregate
function
SELECT boyfrndname,COUNT(*)
FROM lovepair
Group BY boyfrndname
having count(*)>2
--- Now u clear...........
| Is This Answer Correct ? | 4 Yes | 2 No |
Post New Answer View All Answers
Does a specific recovery model need to be used for a replicated database? : sql server replication
How many triggers you can have on a table?
What is an execution plan? How would you view the execution plan?
Why do we backup Active Directory ?
What is SQL Azure Fabric?
How to check if a table is being used in sql server?
What is service broker? : sql server database administration
What is page-level compression?
Mention the different types of triggers?
How can we delete a table in sql server?
What are the differences between INNER JOIN, LEFT JOIN and RIGHT JOIN in SQL Server?
Does full backup break log chain?
What are dml triggers and types of dml triggers?
What are the indexes in sql server?
Can group by be used without aggregate functions?