SQL Server Order Analysis

Source: Internet
Author: User

Select  distinctPurchasedbycontactid asPurchasedbycontactid into#SP fromBasket. Baseordertracker (NOLOCK)whereOrderDate> '2014-2-1'  andOrderDate< '2014-3-1'  andOrdertypeid= the  andOesourceid= 2 andStageid= 10400Select  distinctPurchasedbycontactid asPurchasedbycontactid into#P fromBasket. Baseordertracker (NOLOCK)whereOrderDate> '2014-2-1'  andOrderDate< '2014-3-1'   andOrdertypeid=  the  andOesourceid= 2--The Lost ManSelectA.*  into#NSP from#P (NOLOCK) asawhere  not exists(Select Top 1 1  from#SP asBwhereA.purchasedbycontactid=B.purchasedbycontactid)--detailed information about the lost personSelectC. startdate asStartDate, C. consultantlevelid asLevelcode, I.directsellerid asDirectsellerid, #NSP. Purchasedbycontactid ascontactId into#SNPD fromCONTACTS. Consultants C (NOLOCK)Inner Join#NSP (NOLOCK) on#NSP. Purchasedbycontactid=C. ContactIDInner JoinCONTACTS. Internationalconsultants I (NOLOCK) onC. ContactID=i. ContactID--The loss of the person's orderSelect#SNPD.*, B.orderid asOrderID into#porder fromBasket. Baseordertracker B (NOLOCK)Inner Join#SNPD (NOLOCK) onB.purchasedbycontactid=#SNPD. ContactId andB. OrderDate>'2014-2-1'  andB. OrderDate< '2014-3-1'  andB.ordertypeid=  the  andB. Stageid<> 10400  andB. Oesourceid= 2--Order Maximum ValueSelect#porder. OrderIDMax(O. Stageid) asStageid into#odermax from#porder (NOLOCK)Inner JoinBasket. Ordertrackeraudit O (nolock) onO. OrderID=#porder. OrderIDGroup  by#porder. OrderID-- LastSelect#porder.*, #odermax. Stageid into#last from#porder (NOLOCK), #odermax (NOLOCK)where#odermax. OrderID=#porder. OrderID--Query onlySelect *  from#last (NOLOCK)whereStageid= 10400--stage analysis for failed personnel ordersSelectStageid,COUNT(OrderID) from#last (NOLOCK)Group  byStageidOrder  byStageid--Level analysis for failed personnel ordersSelectcom. purchasercareerlevelid,COUNT(COM. OrderID) from#last (NOLOCK) LInner Joincosmeticordermaster (nolock) COM onL. OrderID=com. orderidGroup  bycom. PurchasercareerlevelidOrder  bycom. Purchasercareerlevelid--Level Analysis of successful ordersSelectcom. purchasercareerlevelid,COUNT(COM. OrderID) fromBasket. Baseordertracker (NOLOCK) botInner Joincosmeticordermaster (nolock) COM onBot. OrderID=com. orderidwhereOrderDate> '2014-2-1'  andOrderDate<     '2014-3-1'   andOrdertypeid= the  andOesourceid= 2 andStageid= 10400Group  bycom. PurchasercareerlevelidOrder  byCom. Purchasercareerlevelid

SQL Server Order Analysis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.