Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想做以下事情:
从表中选择 sum(max(field-10,000,0))
如中,我想总结 field-10,000,但如果 field-10,000 < 0,那么我希望它加 0。
有什么建议么?
卡尔
ANSI语法(由SQL Server、Oracle和支持):MySQLPostgreSQL
ANSI
SQL Server
Oracle
MySQL
PostgreSQL
SELECT SUM(CASE WHEN FIELD < 10000 THEN 0 ELSE FIELD - 10000 END) FROM mytable
使用GREATEST(不支持SQL Server):
GREATEST
SELECT SUM(GREATEST(field - 10000, 0)) FROM mytable