Mysql_ yesterday Nanjing all in-service salesman performance ranking-20170116

Source: Internet
Author: User

#计算南京销售员总业绩排名 data results have been disrupted

#职工信息表包含在职和离职两种状态 Therefore, it is not possible to use this table as the main table, or the data of the departing person is also present in the gross margin table salesperson is limited to yesterday's in-service sales and is consistent with the table salesperson behind the left join check out the corresponding other fields

#@i:[email protected]+1 Growth variable

Select C.*, (@i:[email protected]+1) as rank from (select a. City, B. Working hours, a. Salesperson, B. department, B. Post, B. entry date, DATEDIFF (Current_date, B. Entry date) as in-service days, a. Sales confirmation, a. Gross profit margin from (SELECT city, salesperson, SUM (sales) as sales acknowledgement, sum (gross margin) as margin amount, sum (gross margin)/sum (sales) as gross margin from ' A0 05_account ' WHERE city = ' Nanjing ' and Salesperson in (SELECT name from a032_admin_user WHERE city = ' Nanjing ' and working take several time >current_date and status = ' in service ') G Roup by Salesperson ORDER by SUM (gross margin) DESC) as Aleft JOIN (SELECT name, Department, position, entry date, status, number of hours from a032_admin_userwhere city = ' Nanjing ' and job take Number of times >current_date and state = ' in service ') as B on a. Salesperson =b. Name order by a. Gross margin DESC) as C, (SELECT @i:=0) as it

  

Mysql_ yesterday Nanjing all in-service salesman performance ranking-20170116

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.