sql server - Query to get the accounts shows no movement in February 2016 and the balance is less than $ 2,000.00 -


i try make script query need in sql, try accounts showed no movement in specified month , balance less $ 2000 though try make in group by, not given me idea of how divide customers made movements among did not move accounts, because script this:

declare @fechamovimiento varchar(10) set @fechamovimiento = '0000-00-00'  if not exists (select * [dbo].[cuentasbancarias]                 inner join [dbo].[depositos] b                 on a.cuentaid = b.cuentaid                 inner join [dbo].[retiros] c                 on a.cuentaid = c.cuentaid                 b.fechamovimiento >= @fechamovimiento , b.fechamovimiento >= @fechamovimiento                  , c.fechamovimiento >= @fechamovimiento , c.fechamovimiento >= @fechamovimiento                 ) begin     raiserror('no existen clientes sin movimientos en el mes') end  if exists(select * [dbo].[cuentasbancarias]                 inner join [dbo].[depositos] b                 on a.cuentaid = b.cuentaid                 inner join [dbo].[retiros] c                 on a.cuentaid = c.cuentaid                 b.fechamovimiento >= @fechamovimiento , b.fechamovimiento >= @fechamovimiento                  , c.fechamovimiento >= @fechamovimiento , c.fechamovimiento >= @fechamovimiento                 --and a.saldo < 2000                 ) begin     select * [dbo].[cuentasbancarias] saldo <= 2000 end 

and not correct, although data show, if customer made no move presents results, if single client made movement shows nothing ... , i'm super-confused ... admit not have many sql knowledge

and tried query too:

select cb.* [dbo].[cuentasbancarias] cb not exists (select *               [dbo].[retiros] r               cb.cuentaid = r.cuentaid ,                     r.fechamovimiento >= '2016-02-01' ,                     r.fechamovimiento < '2016-03-01'               ) ,   not exists (select *           [dbo].[depositos] d           cb.cuentaid = d.cuentaid ,                 d.fechamovimiento >= '2016-02-01' ,                 d.fechamovimiento < '2016-03-01'           )          ,     exists (select * [dbo].[cuentasbancarias] saldo < 2000) 

the tables in order:

accountbank

retiro/withdrawal

deposits

enter image description here

select cb.*   [dbo].[cuentasbancarias] cb  cb.saldo < 2000 ,   not exists (select *               [dbo].[retiros] r               cb.cuentaid = r.cuentaid ,                     r.fechamovimiento >= '2016-02-01' ,                     r.fechamovimiento < '2016-03-01'               ) ,   not exists (select *           [dbo].[depositos] d           cb.cuentaid = d.cuentaid ,                 d.fechamovimiento >= '2016-02-01' ,                 d.fechamovimiento < '2016-03-01'           ) 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -