SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
nums = new int[]{1,1,2,3,4,4,4,4,5};
var groupS =nums.GroupBy(x => x);
// for detail view take look at below or click on source link
// https://leetcode.com/problems/majority-element/discuss/2657752/103-ms-faster-than-97.70-of-C-online-submissions-One-Liner
GROUP BY: is used to collaborate
with the SELECT statement to arrange
matching data into groups.
ORDER BY: is for sorting result
either in descending or ascending order.
SELECT country, COUNT(*) AS number
FROM Customers
GROUP BY country;
SELECT
<column_name>,
COUNT(<column_name>) AS `value_occurrence`
FROM
<my_table>
GROUP BY
<column_name>
ORDER BY
`value_occurrence` DESC
LIMIT 1;
SELECT NAME, SUM(SALARY) FROM Employee
GROUP BY NAME;
SELECT <field1, field2, field3…>
FROM <table1_name>
WHERE <condition/expression>
GROUP BY <field1, field2, field3…>
function groupBy(array, keyFn) {
return array.reduce((accumulator, value) => {
const key = keyFn(value);
if (!accumulator[key]) {
accumulator[key] = [value];
} else {
accumulator[key] = [value];
}
return accumulator;
}, {});
}
--- GROUP FUNCTION | MULTI ROW FUNCTION | AGGREGATE FUNCTION
--- COUNT , MAX , MIN , SUM , AVG
Multiple Row Functions (Group functions, Aggregate functions):
(Count, MIN , MAX, AVG, SUM)
will run for multiple rows and return a single value