Monday, 30 June 2014

MySQL IF function

MySQL IF function
Syntax: IF(expr,if_true_expr,if_false_expr)
Example:
SELECT IF(1 = 2,'true','false'); -- false
SELECT IF(1 = 1,' true','false'); -- true

MySQL Query GROUP BY day / month / year

Method I :
SELECT count('id') as cnt,order_status,order_date FROM `product_order` 
group by MONTH(order_date) 
Method II :
SELECT count('id') as cnt,order_status,order_date FROM `product_order` 
group by DATE_FORMAT(order_date, '%m')
Method III:
SELECT SQL_NO_CACHE YEAR(record_date), MONTH(record_date), COUNT(*) FROM stats 
GROUP BY YEAR(record_date)*100 + MONTH(record_date)

SELECT YEAR(date_column), MONTH(date_column), COUNT(*)
FROM date_table
GROUP BY DATE_FORMAT(date_column, '%Y%m')

Google Maps Image APIs

Get Google Map Image for specific latittude & longitude
Static Maps API

<img src="http://maps.google.com/staticmap?size=500x400&markers=11,78&zoom=12">


<img src="http://maps.googleapis.com/maps/api/streetview?size=200x200&location=40.720032,-73.988354&heading=235">