New answers tagged group-by
0
votes
Using GROUP BY together with wildcards for table columns
select distinct
p.product_id, i.filename, pp.*
"select distinct" is a Big Red Flag for me.
select distinct a, b, c
can perform as badly as
select a, b, c group by a, b, c order by a, b, c!
...
-1
votes
Using GROUP BY together with wildcards for table columns
You can use GROUP BY with wildcards if you include primary keys into GROUP BY list. Added in 9.1 https://www.postgresql.org/docs/9.1/release-9-1.html#AEN110817.
0
votes
Postgresql - how to use bool_and with group by
As @a_horse_with_no_name indicated in their comment, the syntax is correct. The query failed for me due to some issues with the client I used.
-1
votes
How to Join two tables with SUM and GROUP BY in SQL server
SELECT Designation, SUM(Qty)
FROM Product P
JOIN sub_product Q
ON Q.Product_ID = P.id
GROUP BY Designation
ORDER BY Designation
? downvoted? LOL
DECLARE @Product TABLE (ID INT, Designation VARCHAR(10)...
3
votes
Accepted
How to Join two tables with SUM and GROUP BY in SQL server
This can be accomplished simply with a JOIN and GROUP_BY clause like so:
SELECT
p.designation,
SUM(ISNULL(sp.quantity, 0)) AS [total quantity]
FROM product AS p
LEFT JOIN sub_product AS sp
...
Top 50 recent answers are included
Related Tags
group-by × 676mysql × 265
postgresql × 130
sql-server × 125
join × 92
aggregate × 64
count × 58
oracle × 55
select × 44
performance × 39
query × 36
greatest-n-per-group × 35
order-by × 34
sum × 33
t-sql × 30
optimization × 26
subquery × 25
query-performance × 20
window-functions × 19
mariadb × 18
distinct × 18
index × 17
gaps-and-islands × 14
mysql-5.5 × 12
pivot × 12