Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[Blue]EXEC[/Blue] spCrossTabPrint
[red]'select title from pubs.dbo.titles t inner join pubs.dbo.sales s on (s.title_id=t.title_id) group by title'[/red][Gray],[/Gray]
[red]'IsNull(sum(qty),0)'[/red][Gray],[/Gray]
[red]'stor_id'[/red]
SELECT title,
[6380] = IsNull(Sum(CASE stor_id WHEN '6380' THEN qty END),0),
[7066] = IsNull(Sum(CASE stor_id WHEN '7066' THEN qty END),0),
[7067] = IsNull(Sum(CASE stor_id WHEN '7067' THEN qty END),0),
[7131] = IsNull(Sum(CASE stor_id WHEN '7131' THEN qty END),0),
[7896] = IsNull(Sum(CASE stor_id WHEN '7896' THEN qty END),0),
[8042] = IsNull(Sum(CASE stor_id WHEN '8042' THEN qty END),0)
FROM pubs.dbo.titles t inner join pubs.dbo.sales s on (s.title_id=t.title_id)
GROUP BY title
[Blue]EXEC[/Blue] spCrossTabPrint
[red]'select pub_name as Publisher, count(qty) as Orders, sum(qty) as Qty from pubs.dbo.sales s inner join pubs.dbo.titles t on (s.title_id=t.title_id) inner join pubs.dbo.publishers p on (p.pub_id=t.pub_id) group by pub_name'[/red][Gray],[/Gray]
[red]'avg(case when price<5 then 5 else price end)'[/red][Gray],[/Gray]
[red]'round(price*qty/100,0)*100'[/red]
SELECT pub_name as Publisher, count(qty) as Orders, sum(qty) as Qty,
[0.00] = Avg(CASE round(price*qty/100,0)*100 WHEN 0.00 THEN case when price<5 then 5 else price end END),
[100.00] = Avg(CASE round(price*qty/100,0)*100 WHEN 100.00 THEN case when price<5 then 5 else price end END),
[200.00] = Avg(CASE round(price*qty/100,0)*100 WHEN 200.00 THEN case when price<5 then 5 else price end END),
[300.00] = Avg(CASE round(price*qty/100,0)*100 WHEN 300.00 THEN case when price<5 then 5 else price end END),
[400.00] = Avg(CASE round(price*qty/100,0)*100 WHEN 400.00 THEN case when price<5 then 5 else price end END),
[700.00] = Avg(CASE round(price*qty/100,0)*100 WHEN 700.00 THEN case when price<5 then 5 else price end END),
[800.00] = Avg(CASE round(price*qty/100,0)*100 WHEN 800.00 THEN case when price<5 then 5 else price end END),
[1000.00] = Avg(CASE round(price*qty/100,0)*100 WHEN 1000.00 THEN case when price<5 then 5 else price end END)
FROM pubs.dbo.sales s inner join pubs.dbo.titles t on (s.title_id=t.title_id) inner join pubs.dbo.publishers p on (p.pub_id=t.pub_id)
GROUP BY pub_name
[Blue]DECLARE[/Blue] @C [Blue]varchar[/Blue][Gray]([/Gray]200[Gray])[/Gray]
[Blue]SET[/Blue] @C[Gray]=[/Gray][red]'C'
[/red][Blue]SET[/Blue] @C[Gray]=[/Gray] [red]'SELect LastName FROM Northwind.dbo.Employees e INNER JOIN Northwind.dbo.Orders o ON (E.EmployeeID=O.EmployeeID) where ShipName<'[/red][Gray]+[/Gray]@C[Gray]+[/Gray][red]' GROUP BY LastName'[/red]
[Blue]EXEC[/Blue] spCrossTabPrint
@C[Gray],[/Gray]
[red]'count(lastname)'[/red][Gray],[/Gray]
[red]'Left(ShipName,8)'[/red]
SELECT LastName,
[Alfreds ] = Count(CASE Left(ShipName,8) WHEN 'Alfreds ' THEN lastname END),
[Alfred's] = Count(CASE Left(ShipName,8) WHEN 'Alfred's' THEN lastname END),
[Ana Truj] = Count(CASE Left(ShipName,8) WHEN 'Ana Truj' THEN lastname END),
[Antonio ] = Count(CASE Left(ShipName,8) WHEN 'Antonio ' THEN lastname END),
[Around t] = Count(CASE Left(ShipName,8) WHEN 'Around t' THEN lastname END),
[Berglund] = Count(CASE Left(ShipName,8) WHEN 'Berglund' THEN lastname END),
[Blauer S] = Count(CASE Left(ShipName,8) WHEN 'Blauer S' THEN lastname END),
[Blondel ] = Count(CASE Left(ShipName,8) WHEN 'Blondel ' THEN lastname END),
[B=lido C] = Count(CASE Left(ShipName,8) WHEN 'B=lido C' THEN lastname END),
[Bon app'] = Count(CASE Left(ShipName,8) WHEN 'Bon app' THEN lastname END),
[Bottom-D] = Count(CASE Left(ShipName,8) WHEN 'Bottom-D' THEN lastname END),
[B's Beve] = Count(CASE Left(ShipName,8) WHEN 'B's Beve' THEN lastname END)
FROM Northwind.dbo.Employees e INNER JOIN Northwind.dbo.Orders o ON (E.EmployeeID=O.EmployeeID)
WHERE ShipName<'C'
GROUP BY LastName