I am trying to create an SQL statement that will essentially calculate points due to a variety of conditions. For example, I have tables: users, followers, pictures
followers and pictures have a user_id, and users has a column called “about”
I want to do some sort of select where I get the sum of:
1) If users.about is not empty, that is worth 100 points
2) If the user owns at least one pictures.type = “something”, that is worth 50 points
3) For every follower that is associated with that user, give 20 points each
So this SQL statement should select the sum of those three calculations. After, I want to use this SQL to create a view that essentially lists the user_id and its associated score.
I have tried various permutations but nothing is working. How would I do this? Thanks!
Here is one way:
Here is a second way: