Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

SQL Query Sort / Total

$
0
0

I am working on an SQL Query and I am not sure what I need to do now.  I have created the following query and it is working.  What I need to do now is to sort this query by further distinctions. What I am attempting to do is to only show one row per PayCode, per Employee.    

This is what I am getting so far:

What I would like to get is one line per EmployeeID per PayCode so I would have this employee on three seperate lines for paycode 37, 44, and 47 with PayUnit totaled and Amount Totaled.

Here is my query so far.  I maybe in left field on this one.  SQL queries are not my strong suit. 

Text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
SELECT DISTINCT p.PayDate, p.employeeNumber, e.Lname, e.Fname, ROUND(e.[PTO-balance], 2) AS [PTO-balance],
p.PayCode, p.PayUnit, p.PayRate, Sum([PayRate]*[PayUnit]) AS Amount, p.Deductions, 
p.SvcDate, p.Comments, p.ProcessID, ROUND(e.[SNP-balance],2) AS [SNP-balance], p.Location, p.PayerType
FROM Employees e INNER JOIN Processing p
ON e.employeeNumber = p.employeeNumber
GROUP BY p.PayDate, p.employeeNumber, e.Lname, e.Fname, e.[PTO-balance], 
p.PayCode, p.PayUnit, p.PayRate, p.Deductions, p.SvcDate, p.Comments,
p.ProcessID, e.[SNP-balance], p.Location, p.PayerType
HAVING (((p.PayDate)='11/20/2013') AND ((p.employeeNumber) < 90000) AND ((p.Location)= 'pd' 
Or (p.Location) Like 'PW' Or (p.Location) Like 'AW' Or (p.Location) Like 'AD' 
Or (p.Location) Like 'HQ' Or (p.Location) Like 'PFM' Or (p.Location) Like 'AFM'
Or (p.Location) Like 'AT' Or (p.Location) Like 'PT' Or (p.Location) Like 'AG' 
Or (p.Location) Like 'PG' Or (p.Location) Like 'AKC' Or (p.Location) Like 'PKC' 
Or (p.Location) Like 'ASL' Or (p.Location) Like 'PSL'))
ORDER BY p.Location;
 
Thanks in advance.




Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>