It went OK i just panicked and forgot all the words, also if anyone interviews please do not ask them to work from a TV on the wall, what is so hard about getting them to use a proper workstation.
Any way from what I remember of the interview questions there were three, solve quadratic equations, formula given, connect to a db in c# and out order the values not to worry about displaying them, and a t-sql question from the pubs database.
Pubs was actually a not that easy to get hold of, a bit of searching and the database can be build by using a script from SQL from the trenches, use the script as the old db files are not compatible with modern iterations of mssql server.
Note code is not perfect as tried to keep to similar timescales
Question 1 & 2
using System;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
var dt = new DataTable();
var connectionString = @"Server=D\SQLEXPRESS;
Database=pubs;Integrated Security=true;";
var query = "SELECT * FROM authors";
var conn = new SqlConnection(connectionString);
var cmd = new SqlCommand(query, conn);
conn.Open();
var sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
conn.Close();
sda.Dispose();
DataView dv = dt.DefaultView;
dv.Sort = "au_lname ASC";
foreach (DataRow row in dv.ToTable().Rows)
{
Console.WriteLine("{0,-15}{1,-15}{2,-15}",
row["au_lname"], row["au_fname"], row["city"]);
}
var anAnswer = quadSolver(1, 9, 18);
Console.WriteLine("The answer is: {0} and {1}",
anAnswer.Item1, anAnswer.Item2);
Console.Read();
}
public static Tuple<double, double> quadSolver(double a, double b, double c)
{
double answer1 = 0.0;
double answer2 = 0.0;
answer1 = ((b * -1) + Math.Sqrt(Math.Pow(b, 2) -
(4 * a * c))) / (2 * a);
answer2 = ((b * -1) - Math.Sqrt(Math.Pow(b, 2) -
(4 * a * c))) / (2 * a);
return new Tuple<double, double>(answer1, answer2);
}
}
}
Question 3
SELECT (au_fname + ' ' + au_lname) AS NAME,
[PUBLISHED TITLES],
[AVERAGE COST],
[LAST PUBLISHED]
FROM authors AS A
JOIN
(
SELECT AU_ID,
COUNT(*) AS [PUBLISHED TITLES],
AVG(price) AS [AVERAGE COST],
FORMAT(MAX(pubdate), 'dd/MM/yyyy') AS [LAST PUBLISHED]
FROM [dbo].[titles] AS T JOIN [dbo].[titleauthor] AS TA
ON T.title_id = TA.title_id
GROUP BY au_id
) AS FT ON A.au_id = FT.au_id
ORDER BY NAME;
No comments:
Post a Comment