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
What are the types of lock supported by ?
Mention the differences between local and global temporary tables.
What is global temp table?
Can two different columns be merged into single column? Show practically?
what are the core components of SSRS?
Where the sql logs gets stored?
What is query optimizer in sql server?
How to write a query with an inner join in ms sql server?
What is an example of a foreign key?
What is change data capture (cdc) in sql server 2008?
Explain what is the difference between a local and a global temporary table?
How to connect to a sql server using odbc_connect()?
How to create a view on an existing table in ms sql server?
What are “lock” hints?
Which sql server table is used to hold the stored procedure scripts?