MYSQL语句5
1.COUNT函数,DISTINCT是不同值。
%%sql SELECT COUNT(DISTINCT Dog_Guid) FROM complete_tests WHERE created_at > '2014-03-01'
2. SUM 函数
%%sql SELECT SUM(ISNULL(exclude)) FROM dogs
3. AVG, MIN, MAX函数
%%sql SELECT test_name, AVG(rating) AS "AVG_Rating", MIN(rating) AS "MIN_Rating", MAX(rating) AS "MAX_Rating" FROM reviews WHERE test_name="Memory versus Pointing"
4.统计时间差 TIMESTAMPDIFF函数
%%sql SELECT AVG(TIMESTAMPDIFF(MINUTE, start_time, end_time)) AS "AVG_time" FROM exam_answers WHERE test_name = "Treat Warm-Up"
%%sql SELECT * FROM exam_answers WHERE TIMESTAMPDIFF(MINUTE, start_time, end_time) < 0
The Safest Way to Get what you Want is to Try and Deserve What you Want.