sql group by sum with condition

SELECT IDDog, 
       COUNT(*) Count,
       SUM(CASE WHEN DogName = 'MAX' THEN Wheight ELSE 0 END) WheightOfAllDogMax
FROM Dogs
GROUP BY IDDog

3
1
Braaedy 125 points

                                    SELECT cust_city, SUM (opening_amt + receive_amt) 
FROM customer 
GROUP BY cust_city;

3 (1 Votes)
0
4.22
9
Imzogelmo 85 points

                                    // Use SQL Group By clause after the Where clause
// Any column in the select list must either be in the Group By clause 
// or part of an agregation statement, like the Sum() statement
// Multiple columns can be included in the Group By Clause seperated by a comma
// Multiple columns stipulate the order tree. Order by 
// first column, then second ... etc

Select LastName, FirstName, Sum(LeaveDays), Max(age)
From EmployeeProjects
Where StartDate > '2020-01-01'
Group By LastName, FirstName

4.22 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
sum sql group by order by sql group by sum sum a column in sql group by How do you sum and group in SQL? select sum and group by sql use sum with group by in sql sql sum group by with case group by one field by sum sql group by by sum sql select sum with group by select sql group by sum sum amount in sql by group group by inside sum sql sum of column group by sql get sum of values in group sql sql group by two columns sum apply sum and group by in sql group by sum result sql sql group by sum with condition where sum with groupby sql sum group by sql server how to group and sum in sql sql select SUM() group by group by sum in sql sql total sum of group by sql server sum group by sql sum group by desc group by and summarise in sql sum with group by and sub query in sql sum with group by in sql server group by sql and sum sql sum grouped column sql sum with group by sql group by with total sql join group by sum how to sum all group by in sql how to sum the group by in sql sql summray group by group by not suming in sql query use sum in sql query without groupBy sql select group by sum sum in sql group by total group by sql sum function without group by in sql sum of column a result query sql with group by sql server group by only with sum sum in sql server with group by sql select sum of group sql select sum group by order by get sum by group sql sql group by where sum sql group by having sum sql group sum by sql sum group sql join and group by sum amount sum query in sql with group by group by result and sum of them sql sql get sum group by join sql sum where group by sql group by column then sum on column sql group by column then sum sql group by then sum calculate sum using group by in sql server sql sum column by group ms sql sum group by group by sum with condition sql sql query with sum and group by sql group by sumtotal sql sum group by is returning null sql sum group by null select sum group by sql sql group by sum values group by sum row values sql group by then sum sql tsql sum group by sql select sum group by group by sql sum sum on group by sql sql sum and group by sql sum group by with where clause sql group by and total sql query group by sum sql groupby sum sql sum query group by group by and sum other column data in sql sum group by in sql complex group by with sum in sql sql sum group by example sql how to sum by group sum all rows in group by sql group by sum of one group as a column sql sum of group by in sql group total sum sql query group by with sum sql sum group by and where group and sum sql sql group by and sum select sum group by only when sum>0 sum with groupbty sql sum top 10 of all group sql group and sum together sql query for sum of group create query using avg,sum and group by sql sum columns values group by other tables sql select group by and sum sql group by sum if sum by group sql sql sum groupby groupby sum sql how to use sum with group by in sql sum group sql group by on new sum fields on where query sum sql group by sql sum in group by query sql select group of cells in row how to sum multiple columns in sql by group by sum with group by in sql sum and group by sql sql sum by group how to use sum with group by in sql server sum sql with group by sum in sql with group by sum at groupby sql server SUM AND DIFFERENCE OF SQL query result grouped by tables querydsl group by sum example group by and sum in sql sql sum query sum data using group by select sum of column sql where and grup by sum with group by sql sum group by same results sum of data wise in sql sql average by group get sum of group sql sql server sum group by how to sum all values qsl qroup by sum in group by sql sql aggregate group by sum of each group by sql how to return group results use group by to get the sum in different table get the sum using group by in sql sql group by column, and make sum sql query sum group by sql get toal of column group by group by then su, group by sum SQL Grouping and aggregate functions sum column in group by select sum group by using group by and sum in sql how to syntax sum and group on sql sql group all the same data together sql group sum group by with sum in sql group by sum pl sql sql group and sum sum of column in sql with group by group by sum count group by sum sql group by and sum group by sum query sum and group by in sql how to use sum and group by in sql sql sum multiple columns group by sql sum group by sum all values group by sql group by and sum sql sum group by 2 columns sql sum group by sql sql group by sum
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source