with tmp(a, b) as ( values (1, 1), (1, 0), (1, cast(null as int)) , (0, 1), (0, 0), (0, cast(null as int)) , (cast(null as int), 1), (cast(null as int), 0), (cast(null as int), cast(null as int))) select * from tmp where a = 1 AND b = 1 order by 1, 2;mysql支持吗
时间: 2023-08-24 21:05:06 浏览: 121
ASP计算str2在str1中出现的次数
这是一个使用 WITH 子句和 VALUES 子句生成一个临时表并从中查询数据的 SQL 语句。MySQL 并不支持 WITH 子句,但可以通过创建临时表或者使用子查询来实现相同的功能。以下是一个使用子查询的示例:
```
SELECT *
FROM (SELECT 1 AS a, 1 AS b UNION ALL
SELECT 1, 0 UNION ALL
SELECT 1, NULL UNION ALL
SELECT 0, 1 UNION ALL
SELECT 0, 0 UNION ALL
SELECT 0, NULL UNION ALL
SELECT NULL, 1 UNION ALL
SELECT NULL, 0 UNION ALL
SELECT NULL, NULL) AS tmp
WHERE a = 1 AND b = 1
ORDER BY 1, 2;
```
注意,MySQL 中的子查询必须包含在括号内,并且必须为其指定一个别名。
阅读全文