0

国のウィジェットのカテゴリに複数ある場合、グループ化してカウント 1 を取得しようとしています。

よりよく説明するために、これまでに取得したコードを次に示します。

select c.Name As Country, w.Description As WidgetName, cat.Description As Category,
  COUNT (wc.Id)AS Clicks  
  from ManufacturerWidgets mw
 join WidgetClicks wc on mw.Id = wc.ManufacturerWidgetId
 join Products p on   wc.ProductId = p.Id
 join Countries c on mw.CountryId = c.Id
 join Widgets w on w.Id = mw.WidgetId
 join Categories cat on cat.Id = p.CategoryId
 where mw.Enabled = 1 and  mw.ManufacturerId = 17 and wc.CreatedAt >= '2013-01-01 00:00:00.000' and wc.CreatedAt <= '2013-07-05 23:59:00.000'
 GRoup By wc.WidgetImpressionId, c.Name,  w.Description,  cat.Description
 HAVING wc.WidgetImpressionId > 0
 order by  c.Name, w.Description, cat.Description

たとえば、次のように返されます。

County   WidgetName   Category    Clicks

Austria  onebysix     computing   1
Austria  onebysix     computing   4
Austria  onebysix     printing    1
Austria  onebysix     printing    3
Austria  onebysix     printing    2

私が返す必要があるのは、各カテゴリの相互作用です。

Austria  onebysix     computing   4  - this would be 1 not 4

そして、最終結果が次のようになるように、それらをカテゴリ別にグループ化する必要があります。

Austria  onebysix     computing   2
Austria  onebysix     printing    3
4

1 に答える 1