Skip to content
Advertisement

Tag: activerecord

How to use a calculated value in Oracle SQL count

I have a column called BIRTH_DATE in my view. I want to calculate the age using that column and today’s date, and count the number of staff in an age bracket. For example: staff between 40 and 49 etc. Other answers in plain SQL statements are also welcome. My code is shown below: I am calculating the age as shown

Find all records which have a count of an association of zero and none-zero

I’d like to get all the images which are being used, and a different query to get all the images that are not being used (based on AssociatedImage). I tried Image.joins(:associated_images).group(‘images.id’).having(‘count(image_id) > 0’) and it returns the correct result. But when I run Image.joins(:associated_images).group(‘images.id’).having(‘count(image_id) = 0’), it returns an empty #<ActiveRecord::Relation []> and I’m not sure why is that. My

Advertisement