Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6467977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:50:49+00:00 2026-05-25T05:50:49+00:00

Suppose we have a table named table1: id name event date 1 name1 f

  • 0

Suppose we have a table named table1:

id  name    event    date
1   name1   f        2010-02-26 21:49:46
2   name2   f        2011-01-21 14:30:26
3   name3   f        2010-05-25 20:51:07
4   name2   r        2011-03-21 21:49:46
5   name4   t        2011-09-15 21:30:26
6   name2   t        2010-01-20 13:07:55
7   name2   t        2011-02-24 20:51:09
8   name1   r        2011-05-20 16:07:55
9   name2   r        2009-07-23 07:51:11
10  name2   r        2011-09-20 21:49:46

A) So I want the result to be in 4 columns:

name    f   r   t
name1   f:1 r:1 t:0
name2   f:1 r:3 t:2

B) moreover I want to be order in relation with the bigest sum of f2, r0.5, t*4 DESC:

C) moreover I want to count the number of events only in a specific period for example last week, month, last 6 months. Can you embeded the below SQL query to yor answer? Are there more types of intervals like months years or hours?

SELECT *
FROM table1
WHERE date BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 WEEK) AND CURDATE()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:50:50+00:00Added an answer on May 25, 2026 at 5:50 am

    You can just use a few self joins (Note: This is untested, since I don’t have an installation of MySQL hanging around, but this should work).

    select a.name, f,r,t
    from(
        select name, count(1) as f,2*count(1) as f_sum
        from table1
        where date >=current_date-30 --or whatever date range you want
        and event='f'
        group by name
        )a
    join(
        select name, ,count(1) as r,0.5*count(1) as r_sum
        from table1
        where date >=current_date-30 --or whatever date range you want
        and event='r'
        group by name
        )b
    on a.name=b.name
    join(
        select name, count(1) as t,4*count(1) as t_sum
        from table1
        where date >=current_date-30 --or whatever date range you want
        and event='t'
        group by name
        )c
    on b.name=c.name
    order by f_sum+r_sum+t_sum desc;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose i have a mysql table name table with fields rank date id The
Suppose you have these tables: Table Name: Salesman Fields: S_ID(Primary Key), Name Table Name:
Suppose I have a table with the following rows id Name Price Supplier 1
Suppose I have a table with a column name varchar(20) , and I store
I can't understand one thing. Suppose I already have these coded entities: [Table(Name =
Suppose we have a table which holds information about person. Columns like NAME or
Suppose we have a NAME table like this: PERSON_ID PART_TYPE VALUE and PERSON_ID is
Suppose I have table A with a field that can be either 1 or
Suppose I have table Person table Employee, which inherits Person. I want to get
Suppose we have a table A: itemid mark 1 5 2 3 and table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.