Click here to Skip to main content
15,901,205 members
Home / Discussions / Database
   

Database

 
QuestionWhats wrong with SQL statement? Pin
gengel2-Mar-10 19:47
gengel2-Mar-10 19:47 
Table 1 (UNITS)
ScanID ScanCount OrderID SerialNo ScanStatus ProductionNo
1981 1294 2 147639NZ301774 SHIPPED 10007627289
There are 1300 SerialNo's for ProductionNo That will end with status 'SHIPPED'

Table 2 (Unit_Logs)
LogID SerialNo ProductionNo Old_Status New_Status
1 147639NZ301774 10007627289 PACKED SHIPPED
There will be 1300 records with status changes from PACKED to SHIPPED

Needed RESULT:
ProductionNo PACKED SHIPPED
10007627289 1300 1300

This is what I have tried:
SELECT UNITS.ProductionNo, COUNT(UNITS.SerialNo) AS SHIPPED,
COUNT(UNIT_Logs.SerialNo) AS PACKED
FROM UNITS JOIN UNIT_Logs
ON UNITS.ProductionNo = UNIT_Logs.ProductionNo
GROUP BY UNITS.ProductionNo, UNITS.ScanStatus, UNIT_Logs.Old_Status
HAVING (UNITS.ScanStatus = 'SHIPPED') AND (UNIT_Logs.Old_Status = 'PACKED')

I added 1 log entry to the table, but the query returns nothing.
Think might need sub query, but not sure where to go from here.
AnswerRe: Whats wrong with SQL statement? [modified] Pin
Jörgen Andersson2-Mar-10 21:48
professionalJörgen Andersson2-Mar-10 21:48 
AnswerRe: Whats wrong with SQL statement? Pin
i.j.russell2-Mar-10 22:04
i.j.russell2-Mar-10 22:04 
GeneralRe: Whats wrong with SQL statement? Pin
gengel2-Mar-10 22:46
gengel2-Mar-10 22:46 
GeneralRe: Whats wrong with SQL statement? [modified] Pin
i.j.russell2-Mar-10 23:35
i.j.russell2-Mar-10 23:35 
GeneralRe: Whats wrong with SQL statement? Pin
gengel3-Mar-10 1:14
gengel3-Mar-10 1:14 
GeneralRe: Whats wrong with SQL statement? Pin
gengel3-Mar-10 1:17
gengel3-Mar-10 1:17 
GeneralRe: Whats wrong with SQL statement? Pin
i.j.russell3-Mar-10 2:00
i.j.russell3-Mar-10 2:00 
QuestionPermission sp_rename Pin
Clas Andersson2-Mar-10 7:23
Clas Andersson2-Mar-10 7:23 
AnswerRe: Permission sp_rename Pin
Mycroft Holmes2-Mar-10 10:52
professionalMycroft Holmes2-Mar-10 10:52 
QuestionSql issue.. Pin
<<Tash18>>1-Mar-10 21:05
<<Tash18>>1-Mar-10 21:05 
AnswerRe: Sql issue.. Pin
J4amieC1-Mar-10 21:15
J4amieC1-Mar-10 21:15 
GeneralRe: Sql issue.. Pin
<<Tash18>>1-Mar-10 22:44
<<Tash18>>1-Mar-10 22:44 
GeneralRe: Sql issue.. Pin
J4amieC1-Mar-10 23:05
J4amieC1-Mar-10 23:05 
QuestionShould I index this? Pin
Mike6543211-Mar-10 9:22
Mike6543211-Mar-10 9:22 
AnswerRe: Should I index this? Pin
Luc Pattyn1-Mar-10 9:34
sitebuilderLuc Pattyn1-Mar-10 9:34 
GeneralRe: Should I index this? Pin
Mike6543211-Mar-10 9:42
Mike6543211-Mar-10 9:42 
GeneralRe: Should I index this? Pin
David Mujica1-Mar-10 10:20
David Mujica1-Mar-10 10:20 
GeneralRe: Should I index this? Pin
Mike6543211-Mar-10 20:30
Mike6543211-Mar-10 20:30 
QuestionLooking for a book on SSIS Pin
Corporal Agarn1-Mar-10 6:30
professionalCorporal Agarn1-Mar-10 6:30 
QuestionConcatenating strings in MS SQL Pin
#Jet1-Mar-10 1:05
#Jet1-Mar-10 1:05 
AnswerRe: Concatenating strings in MS SQL Pin
Corporal Agarn1-Mar-10 6:42
professionalCorporal Agarn1-Mar-10 6:42 
GeneralRe: Concatenating strings in MS SQL Pin
#Jet2-Mar-10 6:22
#Jet2-Mar-10 6:22 
GeneralRe: Concatenating strings in MS SQL Pin
Corporal Agarn3-Mar-10 0:54
professionalCorporal Agarn3-Mar-10 0:54 
QuestionORM with streaming Pin
pebrian2728-Feb-10 23:01
pebrian2728-Feb-10 23:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.