我想你我可以成为一个老屁,但是我已经做了我的SQL(虽然我不是专家),我很确定有更好的方法来写这个。希望你能帮助我。
SELECT
(SELECT MIN(bank_id) FROM bank) AS MinBank,
(SELECT MAX(bank_id) FROM bank) AS MaxBank,
(SELECT bank_id FROM bank WHERE bank_id = $UserID) AS OldBankID,
(SELECT bank_name FROM bank WHERE bank_id = OldBankID) AS OldBankName,
(SELECT bank_interest FROM bank WHERE bank_id = OldBankID) AS OldBankInterest,
(SELECT bank_fees FROM bank WHERE bank_id = OldBankID) AS OldBankFees,
(SELECT bank_pic_url FROM bank WHERE bank_id = OldBankID) AS BankPic
(SELECT bank_id FROM bank HAVING bank_id > (SELECT bank_id FROM users WHERE uid = $UserID) LIMIT 1) AS NewBankID,
(SELECT bank_name FROM bank WHERE bank_id = NewBankID) AS NewBankName,
(SELECT bank_interest FROM bank WHERE bank_id = NewBankID) AS NewBankInterest,
(SELECT bank_fees FROM bank WHERE bank_id = NewBankID) AS NewBankFees,
(SELECT bank_cost FROM bank WHERE bank_id = NewBankID) AS NewBankCost,
FROM dwrel_bank LIMIT 1
基本上它是2个表: (用户)表1 - 检索Bank_ID(客户的旧ID) (银行)表2 - 获取他们的旧银行信息并检索他们的下一个“升级”可用性。
它确实给了我想要的信息,但想知道我是否能以某种方式改进它。
谢谢!
答案 0 :(得分:0)
您可以根据oldBankId更改第一部分,如下所示
select bank_id OldBankId ,bank_name OldBankName, bank_interest OldBankInterest ,
bank_fees OldBankFees, bank_pic_url as BankPic from bank
where bank_Id =(select bank_id from bank where bank_id= $user_id)
你必须使用newBank Id加入它并使用与上面相同的语法