Need some help with SQL Statement about NorthWind Sample


well...i don't know table select , aggregrate function should use here question:

 

- use requiredby date , shippeddate select orders shipped after customer needed them. how many have shipped late?

so sql should this, won't work:

select shippeddate, requireddate, count(shippeddate) [late shipped]

from orders

where shippeddate > requireddate

group shippeddate;

sql server 2005 , up

select o.*, count(shippeddate) on () [late shipped] orders o shippeddate > requireddate

-----------------

the above select late orders , give count of late orders additional column (all same).

if want count each shipped date instead, add partition shippeddate.

also, original code didn't work because needed put requireddate group too.


premature optimization root of evil in programming. (c) donald knuth

naomi nosonovsky, sr. programmer-analyst

my blog


SQL Server  >  Getting started with SQL Server



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........