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

  • SEARCH
  • Home
  • 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 7517813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:34:16+00:00 2026-05-30T01:34:16+00:00

I have a MySQL database-table with the following colums ID status (can contain values

  • 0

I have a MySQL database-table with the following colums

ID
status (can contain values 0, 1, 2)
timepstamp
text
note
owner

I’d like to obtain the following information about the entries of aspecific owner from the table:

 number of entries
 number of entries where status=0
 number of entries where status=1
 number of entries where status=2
 number of entries where LENGTH(note)>0
 minimum timestamp
 maximum timestamp

I used to read the complete datasets and then evaluate them with PHP using

SELECT status, timestamp, LENGTH(note)>0 WHERE owner="name";

I have the problem that some users have so many entries, that that I frequently get an out of memory error if I read the data to PHP. I thought that letting MySQL evaluating the data should be more performat. I could not manage to write a query that could fulfill this task.

SELECT
    MIN(timestamp) AS mintime,
    MAX(timestamp) AS maxtime,
    COUNT(*) AS number,
    ...
WHERE owner="name"

Is it somehow possible to obtain the result in one go? For example with a nested WHERE or IFwithin a COUNT?

    COUNT(WHERE status=0) AS inactive
    COUNT(IF(status=1)) AS active
    ...

How would you solve the problem?

  • 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-30T01:34:18+00:00Added an answer on May 30, 2026 at 1:34 am

    Give this a try –

    SELECT
        COUNT(*) AS total,
        SUM(IF(status=0, 1, 0)) AS stat0,
        SUM(IF(status=1, 1, 0)) AS stat1,
        SUM(IF(status=2, 1, 0)) AS stat2,
        SUM(IF(LENGTH(note)>0, 1, 0)) AS notes,
        MIN(timestamp) AS mintime, 
        MAX(timestamp) AS maxtime
    FROM tbl_name
    WHERE owner="name"
    GROUP BY owner
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a large mysql database table in which one column contains values ranging
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
In a MySQL database I have a table with the following primary key PRIMARY
I have a MySQL database with the following table structure: TransactionType : Transaction_Amount, Transaction_ID,
I have a (mysql) database table with the following columns: NAME | String (Unique)
I have an table in my MySql database that has the following columns: -
I have mysql database with following table... | id | amount | tax |
I have a MySQL database containing the following tables: Table: Professor Attributes: ID, ProfessorName
I have the following mysql table schema: SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; -- -- Database: `network` --
I have a MySQL innodb database at 1.9GB, showed by following command. SELECT table_schema

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.