DB2 SQL Select All With Columns As

荒凉一梦 提交于 2019-12-11 08:39:16

问题


I am working with some SQL queries on DB2. Is it possible to select all the columns in a table and also specify certain conditions using the "as" keyword within that select statement? For example, is this query possible:

select
  *,
  col1 + col2 as sum1,
  col3 - col4 as dif1
from 
  table;

Whenever I attempt this, I am getting the SQL0104 error and it is saying "Token , was not valid. Valid tokens: FROM INTO".

Thank you for your help.

EDIT: This query is running inside an SQLRPGLE program on an AS400.


回答1:


Put your table alias in front of the *. So:

select
  t.*,
  col1 + col2 as sum1,
  col3 - col4 as dif1
from 
  table t;


来源:https://stackoverflow.com/questions/50820397/db2-sql-select-all-with-columns-as

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!