sql >> Databasteknik >  >> RDS >> Mysql

mySQL - uppdatera flera kolumner med ett urval som returnerar flera rader

Update Table1
    Cross Join  (
                Select Min( Case When Z1.Num = 1 Then Z1.postcode End ) As PostCode1
                    , Min( Case When Z1.Num = 2 Then Z1.postcode End ) As PostCode2
                    , Min( Case When Z1.Num = 3 Then Z1.postcode End ) As PostCode3
                From    (
                        Select postcode 
                            , @num := @num + 1 As Num
                        From postcodeTable 
                        Where postcode = 'KY6 IDA'
                        Order By <equation to calculate distance> ASC 
                        Limit 3
                        ) As Z1
                ) As Z
Set nearestPostCode1 = Z.PostCode1
    , nearestPostCode2 = Z.PostCode2
    , nearestPostCode3 = Z.PostCode3
Where Table1.postcode =  'KY6 IDA'


  1. Hur lägger jag till fler medlemmar i min ENUM-typ kolumn i MySQL?

  2. Zend Database Adapter - Complex MySQL Query

  3. Hur sammanfogar man två tabeller i en UPDATE-sats?

  4. Hur man tar bort oönskade ledande karaktärer från en sträng i MySQL