-2

I want to get the sum per day by its specified date, show the sum and the tenant name on it. It should be like this. Does it have any possible way to construct it right??

tenant_id tenant_name  Total Amount
-----------------------------------
  123      SAMPLE         37100

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    The error message is pretty self-explanatory. What happens if you add the tenant_name column to the group by statement? – Sam M Feb 03 '19 at 06:28
  • does it have any chance?? to view ? – Maves Newbie Here Feb 03 '19 at 06:30
  • If there are no duplicates in tenant_info for a given tenant_id, then add tenant_name as well to group by and select clause – Vijiy Feb 03 '19 at 06:36
  • thanks... now I fully understood how its works.. I'll try practicing some more other techniques, Thanks for sharing some knowledge. – Maves Newbie Here Feb 03 '19 at 08:29
  • Does this answer your question? [Column "invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause"](https://stackoverflow.com/questions/18258704/column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggr) – Gert Arnold Jun 02 '22 at 15:27

1 Answers1

1

use both column in group by like below

 group by tenant_id ,tenant_name

so your query will be

select   s.tenant_id ,i.tenant_name,
   sum(s.amount) as total
  from sales_data s left join
      Tenant_info i 
       on s.tenant_id=i.tenant_id
  group by s.tenant_id ,i.tenant_name

Note: maximum db throwns error if you have not put the selection column in group by in times of using aggregate function

Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63