sql >> Database teknologi >  >> RDS >> Mysql

mySQL - opdater flere kolonner med et udvalg, der returnerer flere rækker

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. Kan et bord have to fremmednøgler?

  2. Mysql ERROR 1241 (21000):Operand skal indeholde 1 kolonne(r)

  3. Fremstil en outputfil i fladt format med fast bredde fra en SQL-forespørgsel

  4. Java 11-migrering - createConnectionBuilder() fra PoolDataSourceImpl støder sammen med createConnectionBuilder() fra javax.sql.DataSource