Solved

sql mysql count with condition

Posted on 2008-06-10
3
607 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
  • 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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now