Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sql mysql count with condition

Posted on 2008-06-10
3
Medium Priority
?
613 Views
Last Modified: 2012-06-27
SELECT COUNT( * ) AS `Row` , `Hno`
FROM `member1`
GROUP BY

How can I count the number of person in each house

Hno is the (house number)
Unit  is the group of house
village

CREATE TABLE `member1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Hno` varchar(15) COLLATE utf8_bin DEFAULT NULL,
  `Sname` varchar(80) COLLATE utf8_bin DEFAULT NULL,
  `Ssurname` varchar(200) COLLATE utf8_bin DEFAULT NULL,
  `Unit` varchar(11) COLLATE utf8_bin DEFAULT NULL,
  `village` ENUM('Angtong','Namoung','Lipanoi','Talingam','Maenam','Maret','Bophut') COLLATE utf8_bin DEFAULT NULL,
  `Lastrow` ENUM('0','1') COLLATE utf8_bin DEFAULT '0',
  `DateUp` datetime DEFAULT NULL,
  `TimeAdd` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `remark1` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `datenote` date DEFAULT NULL,
  `remark2` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `useradd` varchar(80) COLLATE utf8_bin DEFAULT NULL,
  PRIMARY KEY  (`id`),
  KEY `Sname` (`Sname`),
  KEY `Ssurname` (`Ssurname`)
) ENGINE=InnoDB AUTO_INCREMENT=36904 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

Open in new window

0
Comment
Question by:teera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 21757190
Is this what you want?
Select Hno, count(*)
from member1
group by Hno

Open in new window

0
 

Author Comment

by:teera
ID: 21757271
Select Hno, count(*)
from member1
group by Hno

when i do like this the house that stay in different village will count together
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 2000 total points
ID: 21757292
Perhaps this:
Select Hno, Unit, village, count(*)
from member1
group by Hno, Unit, village

Open in new window

0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question