Solved

sql statement for count in mysql

Posted on 2008-06-14
3
187 Views
Last Modified: 2010-03-20
SELECT `Ssurname`
, SUM(CASE WHEN ((`status`= '11' ) or  (`status`= '12' ) ) THEN 1 ELSE 0 END) as Rows_Status_11
, SUM(CASE WHEN ((`status`!= '11' ) AND(`status`!= '12' ) ) THEN 1 ELSE 0 END) as Rows_Status_not_11,(select  count(*) as tol where ( (`status`= '11' ) or  (`status`= '12' )) form member_copy1 )
from member_copy1
GROUP BY `Ssurname`
Order by Rows_Status_11 Desc

sql above is not work please help to correct it

may be (select  count(*) as tol where ( (`status`= '11' ) or  (`status`= '12' )) form member_copy1 ) is not correct
0
Comment
Question by:teera
3 Comments
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 150 total points
ID: 21785014
Please print "mysql error" information.

The word, "form" might need to be "FROM" ??
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 21785270
this should do it:
SELECT `Ssurname` 

, SUM(CASE WHEN ((`status`= '11' ) or  (`status`= '12' ) ) THEN 1 ELSE 0 END) as Rows_Status_11

, SUM(CASE WHEN ((`status`!= '11' ) AND(`status`!= '12' ) ) THEN 1 ELSE 0 END) as Rows_Status_not_11

, SUM(CASE WHEN (`status`= '11' ) or  (`status`= '12' ) THEN 1 ELSE 0 END) AS Rows_11_12

from member_copy1 

GROUP BY `Ssurname` 

Order by Rows_Status_11 Desc

Open in new window

0
 
LVL 31

Assisted Solution

by:awking00
awking00 earned 50 total points
ID: 21788964
You have your where clause before the from (form) clause.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

20 Experts available now in Live!

Get 1:1 Help Now