-2

here is my code

select sum(IV.total) as total, 
       IV.sono, 
       sum(SO.total) as total2 
  from tblInvoiceDetail as IV 
       left join tblSO as SO on IV.sono=SO.sono 
 where IV.sono not in (108428,108368) 
 group by IV.sono  
having sum(SO.total) < sum(IV.total) 
 order by IV.sono DESC
Jorge Campos
  • 22,647
  • 7
  • 56
  • 87
user3520445
  • 207
  • 2
  • 6

1 Answers1

1

You can use subqueries to do so:

select IV.sono, ivtotal, sototal
  from (select sono, sum(total) ivtotal from tblInvoiceDetail group by sono) as IV
       LEFT JOIN
       (select sono, sum(total) sototal from tblSO group by sono) as SO 
       ON IV.sono = SO.sono
 where SO.sototal < IV.ivtotal
   and IV.sono not in (108428,108368) 
 order by IV.sono DESC
Jorge Campos
  • 22,647
  • 7
  • 56
  • 87