下面就sql多字段求和並作為sql查詢條件的方法進行了說明供您參考希望對您學習sql查詢方面有所幫助
做一個字段求和的小sql查詢查詢一個表中字段字段和字段之和大於的結果故寫了如下的SQL語句
有一點要注意的是在Where字句中不能有自己運算後得到的字段
sqlstr = "SELECT WIDWWeathergreenColor(SELECT redColor+greenColor+blueColor FROM Weather N WHERE NID = WID) AS AllValue FROM Weather W WHERE (SELECT redColor+greenColor+blueColor FROM Weather N WHERE NID = WID)> ORDER BY ID";
即如下的SQL語句是行不通的說是"至少一個參數沒有被指定值"
sqlstr = "SELECT WIDWWeathergreenColor(SELECT redColor+greenColor+blueColor FROM Weather N WHERE NID = WID) AS AllValue FROM Weather W WHERE AllValue > ORDER BY ID";
From:http://tw.wingwit.com/Article/program/MySQL/201311/29551.html