1

Topic: To unite some requests

Kind time.
There are two requests
[code]
[code] SELECT TOP 1000 [IMEI]
,[Period]
,[Speed]
,[ServerPeriod]
,[Satellite]
FROM [gps]. [dbo]. [TerminalData]
where imei = 356173065104551
and period between ' 2017-09-07 00:00:30.000 ' AND ' 2017-09-30 11:59:59 PM'
order by period
[/code]
[spoiler] [img=http://www.cyberforum.ru/attachments/863582d1504780543] [/spoiler]
And
[code]
SELECT TOP 1000 [IMEI]
,[Period]
,[Sensorid]
,[data]
FROM [gps]. [dbo]. [SensorData]
where imei = 356173065104551
and period between ' 2017-09-07 00:00:30.000 ' AND ' 2017-09-30 11:59:59 PM'
and sensorid = 66
order by period
[/code]
[spoiler] [img=http://www.cyberforum.ru/attachments/863578d1504780259] [/spoiler]
United all in one request
[code]
SELECT TOP 1000 TD.IMEI
, TD.Period
, TD.Speed
, TD.Satellite
, SD.Sensorid
, SD.data
FROM [gps]. [dbo]. [TerminalData] AS TD
LEFT JOIN gps.dbo. SensorData AS SD
ON TD.IMEI = SD.IMEI
AND TD.Period = SD.Period
WHERE TD.imei = 356173065104551
AND TD.period BETWEEN ' 2017-09-07 00:00:30.000 ' AND ' 2017-09-30 11:59:59 PM'
AND SD.Sensorid = 66
ORDER BY TD.period
[/code]
[spoiler] [img=http://www.cyberforum.ru/attachments/863579d1504780259] [/spoiler]
Question: How to add different sensorid in single line that the following turned out?
[spoiler] [img=http://www.cyberforum.ru/attachments/863580d1504780259] [/spoiler]
And, not mandatory to deduce in result columns with numbers sensorid, there is enough only data on each of sensorid.

2

Re: To unite some requests

simpla-jah;
Very informative description. In particular - an inscription "a picture from other site" in spoilers

3

Re: To unite some requests

simpla-jah;
Dynamic pivot

4

Re: To unite some requests

All thanks. Found the decision