Reputation: 1255
I am trying to get the count of rows in my table that meet the requirements.
#<Ahoy::Event:123abc
id: "123abc",
visit_id: "123abc",
user_id: 1,
name: "post_succeeded",
properties:
{"info"=>nil,
"type"=>"post-to-host",
"value"=>0.1,
"partner"=>"Glassdoor",
"request"=>
{"url"=>"http://glassdoor.com",
"params"=>
{"v"=>"1",
"t.k"=>"bac",
"t.p"=>"92",
"action"=>"doJobAlert",
"format"=>"json",
"userip"=>"::1",
"useragent"=>"",
"utm_medium"=>"cpc",
"utm_source"=>"SimplyJobs",
"emailAddress"=>"[email protected]",
"utm_campaign"=>"simplyjobs.com",
"rawLocationName"=>"12345"}},
"success"=>true},
time: Sat, 07 May 2016 19:46:19 UTC +00:00>
Requirements: 'type' => 'post-to-host' AND 'partner' => 'Glassdoor' AND 'success' => true AND 'time' => Time.now.month/day/year
This was my attempt:
Ahoy::Event.where("properties ->> 'type' = ?", 'post-to-host' AND "properties ->> 'partner' = ?", 'Glassdoor' AND "properties ->> 'request' ->> 'success' = ?", true AND time: Time.now.month AND time: Time.now.day AND time: Time.now.year).count
I am not so familiar with SQL, any help is appreciated.
Upvotes: 0
Views: 689
Reputation: 9079
Read up on using where clause in rails The answer will something along these lines
Ahoy::Event.where("properties ->> 'type' = ? AND
properties ->> 'partner' = ? AND properties ->>
'request' ->> 'success' = ? AND time = ?", 'post-to-host', 'Glassdoor', true , Time.now).count
Upvotes: 1