我有以下查询:
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'
启用= 1 和retailerId 我得到完全相同的结果,即使我不应该 - 结果应该少得多。
我敢肯定它是直截了当的,但它让我发疯!任何帮助表示赞赏
编辑:
我实际上需要做的基本上是写 3 条语句来获得结果 - 再次不确定如何执行此操作,但这是语句需要做的(用简单的英语):
从affiliateretailer 表中选择 * where manufacturerid = 46 and enabled = true
从制造商零售商中选择 *,其中零售商是上述选择中剩余的零售商,其中制造商 ID = 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'
编辑 **
对,我有我想要的 Sql 查询......
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
)
这就是你的东西-我实际上在Linq中需要它-如果有人可以为我转换它,我将不胜感激......我会试一试!