Solved

sql statement for count in mysql

Posted on 2008-06-14
3
193 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
[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
3 Comments
 
LVL 110

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 143

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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