i am looking at this site:
set nocount on
DECLARE @endDate date
SELECT @endDate = max(CreationDate) from Posts
set nocount off
SELECT TOP 50
Id AS [User Link], Reputation, Days,
Reputation/Days AS RepPerDays
FROM (
SELECT *,
CONVERT(int, @endDate - CreationDate) as Days
FROM Users
) AS UsersAugmented
WHERE
Reputation > 5000
ORDER BY
RepPerDays DESC
i am also a beginner at SQL. i have the following questions about this code:
- is this mysql or mssql?
- what does this do?
set nocount off - why is this in brackets?
[User Link] - what does this do?
CONVERT(int, @endDate - CreationDate) as Days
thanks!
1. It’s Microsoft SQL Azure Database, but the syntax (Transact-SQL or T-SQL) is the same as for SQL Server (because Azure Database is “based on SQL Server technologies”).
2. This is described in the T-SQL documentation for SET NOCOUNT.
3. You need to put square brackets around a column name if it contains any character that would confuse the parser. In this case it is necessary because of the space.
4. To understand
CONVERT(int, @endDate - CreationDate) as Dayslet’s split it into smaller pieces and handle them separately:@endDate - CreationDatecalculates the time between the most recent post and the date that the user’s account was created. This gives the time that the user’s account has existed up to the last data dump.CONVERT(int, @endDate - CreationDate)converts the result of the previous calculation to an integer, measured in days.as Daysis an alias so that the result is easy to read.