Microsoft
Software
Hardware
Network
Question : T-SQL help table join
I have two tables:
T1.WORK_ID T1.COMPANY_NAME T1.work_LOCATION
1 TEST_COMPANY1 TEST_COMPANY1_LOC1
2 TEST_COMPANY1 TEST_COMPANY1_LOC2
3 TEST_COMPANY1 TEST_COMPANY1_LOC3
4 TEST_COMPANY2 TEST_COMPANY2_LOC1
5 TEST_COMPANY2 TEST_COMPANY2_LOC2
6 TEST_COMPANY2 TEST_COMPANY2_LOC3
T2.WORK_ID T2.start_date_time T2.end_date_time
1 2010-01-02 8:00 2010-01-02 11:00
2 2010-01-03 8:00 2010-01-03 10:00
3 2010-01-05 8:00 2010-01-05 11:30
4 2010-02-10 8:00 2010-02-10 09:30
5 2010-02-12 8:00 2010-02-12 12:00
6 2010-02-15 8:00 2010-02-15 10:30
The result I am looking for is:
COMPANY_NAME START_DATE_TIME END_DATE_TIME
TEST_COMPANY1 2010-01-02 8:00 2010-01-05 11:30
TEST_COMPANY2 2010-02-10 8:00 2010-02-15 10:30
note:
DISTINCT BY T1.COMPANY_NAME, EARLY_START_DATE_TIME, LAST_END_DATE_TIME
The T1 and T2 match by work_id
Thank you,
Answer : T-SQL help table join
SELECT T1.COMPANY_NAME, MIN(T2.start_date_time) AS START_DATE_TIME, MAX(T2.end_date_time) AS END_DATE_TIME
FROM T1 INNER JOIN
T2 ON T1.WORK_ID = T2.WORK_ID
GROUP BY T1.COMPANY_NAME
Random Solutions
Adobe Photoshop 6.0
Comparing the latest date
DOS Bat File Copy a File with Date Timestamp
Adding URL Parameter
windows xp 64 bit on APPLE IMAC 27 inch
Disabling software restriction policy
Having a webservice use a Session variable that is set in the project before the webservice is called.
How to make WPF button background color silver?
"File Helper" reporting - Your system may have upopenable files - Why?
mysql stored proc parameter