#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Help writing SQL query


    Hi, I'm new to sql and need help writing a query with two tables.

    I have Table 1 called wp_frm_item_metas with columns of meta_value, field_id, and created_at

    Table 2 is called wp_users and has a column called user_registered

    In Table 1:
    meta_value has a value called "Science" in it
    field_id has a value called "389" in it
    created_at has dates in it with a format of 2013-05-16 19:34:44

    In Table 2:
    The user_registered column also has dates with the same format of 2013-05-16 19:34:44

    I'm trying to do a query that shows a COUNT of the records that have both "Science" and "389" from Table 1 that are equal or greater than the user_registered date that's in Table 2

    Help is VERY appreciated!
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    Are you doing this for a particular user? Because what you want doesn't make sense if you're trying to do it for all users.
    I also suspect there's more going on in the database than you're accounting for.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by requinix
    Are you doing this for a particular user? Because what you want doesn't make sense if you're trying to do it for all users.
    I also suspect there's more going on in the database than you're accounting for.
    I'm trying to display the total number of Science assignments that have been provided since a user has registered/started their account. So I can show in their reporting that they've completed for example 5 out of 10 assignments. It's the "10" that I'm trying to display.

    In wp_frm_items_meta table, I'm not seeing data in there that would let me isolate the query to a specific user, but it does have the created_at field; therefore, I thought I'd be able to use wp_users table somehow to match any user that started their account by a certain date to pull the data. So, the result could be unique to a user, but I would say it's also unique to the date that any users may have started an account.

    There are other fields in each of these tables, one of them being user_login from the wp_users table. Do you think it's possible to pull this data based on these tables?

    Thanks!

IMN logo majestic logo threadwatch logo seochat tools logo