Trilochan Parida Profile picture
I'm an entrepreneur who speaks both sales and code fluently—basically, I sell the dream and then build it myself!

Jul 14, 2020, 6 tweets

The GROUP BY clause groups a set of rows into a set of summary rows by values of columns or expressions.

The GROUP BY clause returns one row for each group. In other words, it reduces the number of rows in the result set.

We often use the GROUP BY clause with aggregate functions such as SUM, AVG, MAX, MIN, and COUNT.

The aggregate function that appears in the SELECT clause provides information about each group.

Example-1: GROUP BY with aggregate functions

SELECT
status, COUNT(*)
FROM
orders
GROUP BY status;

Example-2: MySQL GROUP BY with HAVING clause

SELECT
YEAR(orderDate) AS year,
SUM(quantityOrdered * priceEach) AS total
FROM
orders
WHERE
status = 'Shipped'
GROUP BY
year
HAVING
year > 2003;

Latest MySQL is not supporting GROUP BY without aggregate functions, to enable GROUP BY execute bellow command,

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

💕🙏

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling