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
Why does a SAV 10.2.4.4000 new installation show up as 10.1.9.9000?
DAG & CAS array configured but it's not failover
User's Web-Based AOL Mail is sending spam to all his contacts
Problem with Microsoft Transporter Suite
Scheduled Tasks to perform daily export of W2K3 server Event Viewer Logs.......
setting text of a dynamic dom element using javascript
Microsoft Information Store stalling issues
Exhange 2003 mailbox permissions
javax.servlet.jsp.JspExcep
tion: Cannot retrieve definition for form bean null on action
SQL Stored Procedure pass in a list