Posts

Showing posts from September, 2018

Inside Group by

Group by <SameColumn>, this basically  group the rows having same column value. lets say, --> Group by department, this this will club all the rows which has same department, and it will have some sort of list of list, 1st position, list of 6 rows, from CSE department 2nd row,      list of 2 rows from ECE department Now in these rows, you can only perform some aggregate funtion and display it, you can display employee name of department as output, because one collection, say 1st position, may have 6 rows each having different employee name, what it will display? i.e. you should/can perfrom only agregate function on this grouped by list. select count(CustomerID) as countryhead,country,city from customers group by Country,city order by countryhead DESC; countryhead Country City 6 UK London 5 Mexico México D.F. 4 Brazil São Paulo 3 Argentina Buenos Aires 3 Brazil Rio de Janeiro 3 Spain Madrid

Logic of "group by

If you use any aggregate function, and also wants to display another column along size it, you must use "GROUP by" select char_length(city) as citynamesize,city from station group by city order by citynamesize DESC; 21 Marine On Saint Croix 18 West Baden Springs 17 Frankfort Heights 3 Roy 3 Lee SELECT count(CustomerID), CustomerName,City FROM Customers where CustomerName Like '%Ho%' Group by City ; If you run below querry, it will give 7 in count column, because it's illogical, you can find the people/row, whos names contains "Ho", but against what, you cant display 7|Hosa ? SELECT count(CustomerID), CustomerName FROM Customers where CustomerName Like '%Ho%'; So that's why it should be more meaningful, like display the names and count of people, whos name contains "Ho" per city, So against each city, you will find count of people. whos name starts with "Ho" but again displaying names doesn't make...