Count rows with a where condition in MySQL

DCJones

I am trying to count the number of rows in a table where a condition is true.

My query is:

SELECT
COUNT(SeqID0101),
COUNT(SeqID0102),
COUNT(SeqID0103),
COUNT(SeqID0104),
COUNT(SeqID0105),
COUNT(SeqID0106),
COUNT(SeqID0107),
COUNT(SeqID0108),
COUNT(SeqID0109),
COUNT(SeqID0110)
FROM
PH001_Hist
WHERE
SeqID0101 = 1 OR SeqID0102 = 1 OR OR SeqID0103 = 1 OR SeqID0104 = 1 OR SeqID0105 = 1 
OR SeqID0106 = 1 OR SeqID0107 = 1 OR SeqID0108 = 1 OR SeqID0109 = 1 OR SeqID0110 = 1

I keep reading other posts but can't find an answer to this issue.

Abhik Chakraborty

The query that you have does not look correct and you can not count this way. However you can do something as

select
sum(SeqID0101 = 1) as SeqID0101,
sum(SeqID0102 = 1) as SeqID0102,
sum(SeqID0103 = 1) as SeqID0103,
sum(SeqID0104 = 1) as SeqID0104,
sum(SeqID0105 = 1) as SeqID0105,
sum(SeqID0106 = 1) as SeqID0106,
sum(SeqID0107 = 1) as SeqID0107,
sum(SeqID0108 = 1) as SeqID0108,
sum(SeqID0109 = 1) as SeqID0109,
sum(SeqID0110 = 1) as SeqID0110
from 
PH001_Hist

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MYSQL Count Rows Where Max

From Dev

PostgreSQL - select count(*) for rows where a condition holds

From Dev

How to count rows in table with condition WHERE?

From Dev

MYSQL DELETE WHERE CONDITION (COUNT = 0)

From Dev

Delete Rows Where Condition is Met? MySQL

From Dev

Select rows using a count condition inside a where clause

From Dev

Count of rows for every date between a two dates MySQL where no rows

From Dev

Count rows based on a condition

From Dev

MySQL Count from a table where condition on the last row of a related table

From Dev

MySQL - Count rows where some have more than 1 quantity

From Dev

MySQL: how to show rows where count is 0 using group by?

From Dev

MySQL Count All Rows and Count All Rows Where field1 = 1

From Dev

MySQL Count All Rows and Count All Rows Where field1 = 1

From Dev

MySQL count rows where column value is same and select them where count is greater than 2

From Dev

Mysql distinct with count with condition

From Dev

Count with condition-mysql

From Dev

Python: Removing Rows on Count condition

From Dev

Using IF to count rows and insert with condition

From Dev

Mysql Query: returning rows where all preceding rows in group match a condition

From Dev

Mysql Query: returning rows where all preceding rows in group match a condition

From Dev

sql - count with multiple WHERE condition

From Dev

Ternary in WHERE condition (MySQL)?

From Dev

Mysql custom where condition

From Dev

MySQL - nested where condition

From Dev

Mysql alias in where condition

From Dev

mysql, use condition in "where"

From Dev

MySQL query WHERE condition

From Dev

MySQL Order by count of rows

From Dev

Mysql Count and Sum Rows

Related Related

HotTag

Archive