mysql - 将 mysql 查询转换为 sql server 查询

标签 mysql sql sql-server

我想将以下 mysql 查询转换为 sql 查询。我想在 sql server 中使用 If 条件

SELECT
foodName,
IF( foodPrice>2000, 'Expensive', 'Cheap') as fpDesc,
discountPercent
FROM restaurant.foods;

最佳答案

如您所见,

if 是 MySQL 专有的。执行此操作的标准方法是 case

CASE WHEN foodPrice > 2000
     THEN 'Expensive'
     ELSE 'Cheap'
 END

另请参阅:http://modern-sql.com/feature/case

关于mysql - 将 mysql 查询转换为 sql server 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47346239/

相关文章:

sql - Oracle 条件存储过程中的 WHERE

c# - 使用另一个线程将数据从数据库加载到组合框

sql - "IN"Sql Server 中的子句限制

java.sql.SQLException : Access denied for user 'root' @'192.168.3.33' (using password: YES) on jelastic

php - Codeigniter 检查 index.php 文件中是否已登录

php - 从 Wordpress 数据库中检索重音符号而不是逗号

mysql - 选择组中不同但整体不同的值

javascript - 使用 Sequelize 将多个参数安全地发送到 IN 子句以进行原始查询

Python 和 SQL 批量插入

php - 用于让我的注销按钮通过 php 工作的最佳 html 表单是什么