/*1.Using the posts table, find out the number of posts (...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

/*1.Using the posts table, find out the number of posts (as num_posts), 
the minimum creation date (as min_date), the maximum creation date (as max_date), 
and average score (as avg_num_posts) */

SELECT COUNT(*),
	MIN(CreationDate) AS min_date,
	MAX(CreationDate) AS max_date,
	AVG(score) as avg_score
FROM posts;

/* 2.Use the badges table to show badge name (as name) 
and the number of people who won it (as badge_count), 
limiting results to badges with at least 20 winners.*/

SELECT name,
    COUNT(*) AS badge_count
FROM badges
GROUP BY name
HAVING COUNT(*) >=20;

/* 3.Find users who report being located in 'New York, NY’ city. 
Report id, displayname, and location in your result set.*/

SELECT id,
    DisplayName,
    Location
FROM users
WHERE Location = 'New York, NY';

/* 4.We want to know how many posts were written each month. 
Count the number of posts by year-month. Please note that by year-month, 
I mean that May 2013 and May 2014 should be considered as different year-months. 
The result table should show year, month and count and order results by year, month.*/


SELECT 
    COUNT(id) AS post_count
FROM posts;

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results