Count with IF condition in MySQL query

Use sum() in place of count() Try below: SELECT ccc_news . * , SUM(if(ccc_news_comments.id = ‘approved’, 1, 0)) AS comments FROM ccc_news LEFT JOIN ccc_news_comments ON ccc_news_comments.news_id = ccc_news.news_id WHERE `ccc_news`.`category` = ‘news_layer2’ AND `ccc_news`.`status` = ‘Active’ GROUP BY ccc_news.news_id ORDER BY ccc_news.set_order ASC LIMIT 20

Get number of digits with JavaScript

length is a property, not a method. You can’t call it, hence you don’t need parenthesis (): function getlength(number) { return number.toString().length; } UPDATE: As discussed in the comments, the above example won’t work for float numbers. To make it working we can either get rid of a period with String(number).replace(‘.’, ”).length, or count the … Read more

How can I tell how many objects I’ve stored in an S3 bucket?

Using AWS CLI aws s3 ls s3://mybucket/ –recursive | wc -l or aws cloudwatch get-metric-statistics \ –namespace AWS/S3 –metric-name NumberOfObjects \ –dimensions Name=BucketName,Value=BUCKETNAME \ Name=StorageType,Value=AllStorageTypes \ –start-time 2016-11-05T00:00 –end-time 2016-11-05T00:10 \ –period 60 –statistic Average Note: The above cloudwatch command seems to work for some while not for others. Discussed here: https://forums.aws.amazon.com/thread.jspa?threadID=217050 Using AWS Web … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)