SQL空查询结果 [英] SQL Empty query results

查看:139
本文介绍了SQL空查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,我有一个这样的表:

Imagine I have a table like this one:

CREATE TABLE marcas
(
  id_marca integer,
  marca character varying
));

我想进行查询,但是每个字段的值都为空。

I would like to make a query but get the value in every field empty.

我知道可以这样解决:

SELECT''as id,''as marca FROM marcas

问题是我有很多表,其中一些有超过100个字段...
需要一个SQL语句,它可以获得表的所有行字段,但是以一种简单的方式...

The problem is that i have plenty of tables and some of them have more than 100 fields... I need a SQL statement that could get all the row fields of a table but empty and in an easy way...

推荐答案

是在每一列中获取 NULL 的一种方法。它使用左外连接与失败条件:

Here is one method to get NULL in every column. It uses left outer join with a failing condition:

select t.*
from (select 1 as val
     ) v left outer join
     table t
     on 1 = 0;

编辑:

这在Access,这是一个挑战。表达式选择1作为val 不起作用。以下内容应该:

If you want to do this in Access, that is a challenge. The expression select 1 as val doesn't work. The following should:

select t.*
from (select max(1) as val
      from table as t 
     ) as v left outer join
     table as t
     on val = 0;

这也应该在Postgres中使用,但它有不必要的开销。

This should also work in Postgres, but it has unnecessary overhead.

这篇关于SQL空查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆