Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'd track your unique users in one table and unique badges in another then create a cross reference table to relate them.</p> <p>A user can have many badges and a badge can have many users.</p> <pre><code>create table users ( id int, name varchar ) create table badges ( id int, badge_name varchar ) create table user_badges_xref ( user_id int, badge_id int ) </code></pre> <p>Statistics that might affect whether a user earns a badge are tracked as a part of the administration of the site. so something like an answer being accepted would be in a schema that relates questions &amp; answers. in order to display the answer and the owner of the answer, there would be a relationship to the user table and triggers that would check for badge conditions whenever a change was made.</p> <blockquote> <p>I'm not asking how to award badges. I'm asking how to store criteria within the database.</p> </blockquote> <p>So you want to store the logical operation required to determine if a badge is earned in a field somewhere?</p> <p>I think agree with the other poster that criteria should be a part of the business logic. That logic can be on the app side or within a trigger. I think that's a matter of style.</p> <p>If you were really married to the idea of storing the criteria in a field, I'd store it as parameterized SQL and run it dynamically.</p> <p>So this sort of thing would be in your criteria field:</p> <pre><code>select "Badge Earned" from all_posts where user_id = @user_id having count(*) &gt; 10000 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload