Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi there!
I need some advice… I need agood solution to select inactive donors for my customer?
Definitions
Datamodel
FactTable
Theresult must be like this… The table must have records for all months after January2006 and then a record for each relationname, each payment method eachproductname
Year | Month | relationName | paymentMethod | ProductName | Active |
---|---|---|---|---|---|
2012 | 3 | Customer1 | cash | product1 | inactive |
2012 | 3 | Customer1 | creditcard | product2 | inactive |
2012 | 3 | testJan2008klant | cash | product1 | inactive |
2012 | 3 | Customer2 | cash | product1 | active |
In SQL Ihave a working query, which is this one
selectmin(YEAR(firstDayOfMonth))as dYear,
min(month(firstDayOfMonth))as dMonth,
min(r.name)as relationName,
min(bw.name)as paymentMethod,
MIN(p.name)as productName,
--here asubquery to determine (in)activity
--whenthere was a payment in the last 12 months, you're active, else inactive
case when(
selectCOUNT(id) From fact f
where
paymentDate>=
(
DATEADD(month,-11, ( cast(min(YEAR(firstDayOfMonth))as varchar(40)) ) + '-'+ cast( min(month(firstDayOfMonth)) asvarchar(40))+'-01')
)
andpaymentDate <=
DATEADD(DD,-1, DATEADD(M, 1,
CAST(min(YEAR(firstDayOfMonth))AS VARCHAR(4)) + '/' +
CAST(min(month(firstDayOfMonth)) ASVARCHAR(2)) + '/01'))
and MIN(r.id)=f.idRelation --filter on relation
andMIN(bw.id) =f.idpaymentmethod--filter paymentmethod
) >0then 'Active' else 'Inactive' end as active
FROM
MonthYear my
full outer join fact f
on 1=1 --on purpose a cartesianproduct: I want all combinations of customer, year and month
left join relation r on r.id =f.idRelation
left join product p on p.id =f.idproduct
left join paymentmethod bw on bw.id= f.idpaymentmethod
group by
YEAR(my.firstDayOfMonth),
Month(my.firstDayOfMonth),
idrelation,
idproduct,
idpaymentmethod
order by
YEAR(my.firstDayOfMonth)desc,
Month(my.firstDayOfMonth)desc,
activedesc
In otherwords: can this SQL query also be run in Qlikview loadscripts (when loadingfrom QVD’s)?
I’d like to hear: hope my problem is declared well enough… If not, please let me knowhow I can make it more clear…?
sdfasdf
Hi there. I got no answers yet (I can imagine that my question was formulated too large...)
Lets retry:
Can I use a subquery in the Qlikview loadscripts, like it can be done in SQL in the way shown below?
select
'Field 1' as field1,
(select COUNT(id) From factTable ) as field 2
I (preferably) don't use SQL as the customer has a bunch of QVD files that we have to use as source...
(the reason for asking: I have a nice working SQL question with a subquery, and hope it can be done in the Qlikview script as well)
Any help is appreciated (even when perhaps the question is not clear enough...
Hi, Roberto.
It's not possible to use subqueries like this.
You can run it directly on the database, but as you said in your case you already have qvds.
You can use aggregation expressions and joins to recreate your original query.
For exampe:
Users:
load user_id
from...
tmpAccess:
Load user_id, count( id_access) as qtty
from. ...
left join( Users)
Load * from tmpAccess;
drop table tmpAccess ;
Hope this helps,
Erich
This is a decent solution in my view. Thanks Jason