How to find the date diffrence greater than a particular number using mysql?
eg: date difference is greater than 10
Ans:DATEDIFF( );
eg:SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), dob)),
"%Y")+0 AS age from sometable
Q.Find the records match in table,and also stop when first match occurs?
eg: date difference is greater than 10
Ans:DATEDIFF( );
eg:SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), dob)),
"%Y")+0 AS age from sometable
Q.Find the records match in table,and also stop when first match occurs?
The limit 1 on each one keeps the database from pulling up 50,000 Bob records just toshow you one of them. Q .how to optimize sql querys? Ans: * Use primary keys * Avoid select * * Be as specific as you can when building your conditional statements * De-normalisation can often be more efficient * Table variables and temporary tables (where available) will often be better than using a large source table * Partitioned views * use indices and constraints Q.Difference b/w having and where? If a condition refers to an aggregate function, put that condition in the HAVING clause. Otherwise, use the WHERE clause. Here's another rule: You can't use HAVING unless you also use GROUP BY. SELECT state,SUM(baldue) FROM Test GROUP by state HAVING SUM(baldue) > 0 ORDER BY state |
0 comments:
Post a Comment
Thanks for your valuable Comment