I have the following query:
select distinct(ab.id)
from WidgetClicks ab
join ManufacturerWidgets aa
on ab.ManufacturerWidgetId = aa.Id
join ManufacturerRetailers ad
on aa.ManufacturerId = ad.ManufacturerId
join Products ac
on ab.ProductId = ac.Id
where ad.Enabled = 0
and ad.RetailerId = 189
and aa.ManufacturerId = 46
and aa.CountryId = 72
and ac.Id = 6914
and ab.CreatedAt >= '2011-10-31 00:00:00.000'
and ab.CreatedAt <= '2012-03-31 00:00:00.000'
With enabled = 1 and the retailerId I get exactly the same results even though I shouldn’t – the results should be a lot fewer.
I’m sure its something straightforward but its driving me mad! any help appreciated
EDIT:
What i actually need to do is basically write 3 statments to get the results – again not certain how to do this but this is what the statment needs to do (in plain english):
-
From the affiliateretailer table select * where manufacturerid = 46 and enabled = true
-
Select * from manufacturerRetailer where the retailers are the ones remaining in the above selection where manufacturerid = 46
-
Select * from widgetClicks join on retialer d where productid = abc and wc.CreatedAt >= ‘2011-10-31 00:00:00.000’ and wc.CreatedAt <= ‘2012-03-31 00:00:00.000’
Edit **
Right i’ve got the Sql query that i want…
SELECT COUNT(*)
FROM WidgetClicks
WHERE CreatedAt >= '2011-10-31 00:00:00.000'
and CreatedAt <= '2012-03-31 00:00:00.000'
and ProductId = 6914
AND RetailerId in (
SELECT RetailerId
FROM AffiliateUpdateFiles auf
WHERE auf.Enabled = 1 AND auf.ManufacturerId = 46 and RetailerId <> 189
)
AND ManufacturerWidgetId in (
select id
from ManufacturerWidgets
where ManufacturerId = 46 and CountryId = 72
)
Here’s the thing thoug – I actually need it in Linq – if anyone can convert it for me it woudl be appreciated… i will be having a go!
Here is the solution for converting the above to Linq: