sql >> データベース >  >> RDS >> Mysql

mySQL-複数の行を返すselectで複数の列を更新します

    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. Oracleでsys_refcursorを使用して動的SQLを作成する方法

    2. 複数のSQLステートメントを使用するMySQLConnectorJ

    3. Postgresでjsonb配列要素を結合する方法は?

    4. PHP/MySQLでの再帰的コメントの実装