newphpbees Posted February 21, 2012 Share Posted February 21, 2012 Good day! Hi, I encountered problem in Count. I have this data: REFNUM----LOT_CODE----PCODE--wip_chemicalweighing--wip_compounding-------wip_extrusion--wip_forming--wip_deflashing 000001----000001P35M--P35M---0.00------------------0.00------------------0.00-----------0.00---------40.00--------- 000002----000002P35M--P35M---73.30-----------------NULL------------------NULL-----------NULL---------NULL--------- and I have this code: SELECT PCODE, COUNT(LOT_CODE) AS lot_chemicalweighing, COUNT(wip_chemicalweighing + wip_compounding + wip_extrusion + wip_forming + wip_deflashing) AS virtual FROM kanban_data WHERE wip_chemicalweighing != '0.00' OR 'NULL' AND wip_compounding != '0.00' OR 'NULL' AND wip_extrusion != '0.00' OR 'NULL'AND wip_forming != '0.00' OR 'NULL' AND wip_deflashing != '0.00' OR 'NULL' GROUP BY PCODE; And the output of this code is : PCODE-- lot_chemicalweighing---virtual---- P35M----1----------------------0-------- the lot_chemicalweighing is correct but the virtual is wrong, because it should be 2 because I have 1 data in wip_chemicalweighing and 1 in wip_deflashing. Thank you Link to comment https://forums.phpfreaks.com/topic/257456-mysql-count-problem/ Share on other sites More sharing options...
The Little Guy Posted February 21, 2012 Share Posted February 21, 2012 Your second count should look like this: (COUNT(wip_chemicalweighing) + count(wip_compounding) + count(wip_extrusion) + count(wip_forming) + count(wip_deflashing)) as virtual Link to comment https://forums.phpfreaks.com/topic/257456-mysql-count-problem/#findComment-1319566 Share on other sites More sharing options...
newphpbees Posted February 23, 2012 Author Share Posted February 23, 2012 Thanks for your code, now I'm thinking on my where clause to get only the non-zero and null. Thank you Link to comment https://forums.phpfreaks.com/topic/257456-mysql-count-problem/#findComment-1320257 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.