select - SQL Server 2012 Express How do I pull information from one column and compare it to another with an expression restriction -


sorry, i'm trying word correctly. i'm trying compare 1 column table column table check , see how many rows in second column. i'm using northwind sample database , question follows.

list customers (include customerid , company name) have placed less 5 orders.

  • include customers have placed 0 orders. name count field "ordercount."
  • order number of placed orders in reverse order.

i'm absolutely stuck on this.

this might have names little off.

    select c.customerid, c.[company name], isnull(ordersum.ordercount,0) ordercount     customers c     left join (select customerid, count(1) ordercount                orders                group customerid) ordersum     on c.customerid = ordersum.customerid     isnull(ordersum.cnt, 0) < 6     order 2 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -