Solved

sql statement for count in mysql

Posted on 2008-06-14
3
189 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 109

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 32

Assisted Solution

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

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help on t-sql 2012 10 55
SQL Syntax 5 37
Display images from mysql blob type (Not working) 9 31
performance query 4 24
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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