Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Inner Join or Merge in a single Table?

$
0
0

I have a Single table with

City            date               type     vlCC       vlVV           key

London    24-01-2014        CC       blue                         key1
London    25-01-2014        VV                    yellow         key4
London    24-01-2014        VV                    green          key2
Lisbon     24-01-2014        CC       green                      key5
Lisbon     24-01-2014        VV                     red            key6
London    25-01-2014        CC       black                        key3

My first approach was a inner join but hanged here.

SELECT distinct p.city, p.date, p.type FROM Cities AS P INNER JOIN Cities AS P2
ON P.City = P2.City AND P.Date = P2.Date   AND P.type <> P2.type and P.Date > GETDATE() order by   p.city, p.date,  p.type

My wanted output is

London     24-01-2014       blue        green      key1      key2
Lisbon      24-01-2014        green      red          key5      key6
London     25-01-2014       black       yellow     key3      key4

(ordered by   p.city, p.date,  p.type)

It means I want to "merge" the rows by city and date and order it like that (city,date )

Thanks


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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