select aggregate function and all other columns

喜你入骨 提交于 2019-12-11 01:46:16

问题


How do I select all columns in a table and an aggregate function in a convenient way?

I.e. say that I have a table with 100 columns, and I want to send the following

SELECT Max(Columns 44), ALL OTHER COLUMNS
FROM zz
Group by ALL OTHER COLUMNS 

Thanks!


回答1:


To select all columns from the table is:

select * from zz;

To select a maximum from the table is

select max(column44) from zz;

The two combined:

select zz.*, (select max(column44) from zz) as maxcol44
from zz;

If you want to omit column44 in your result rows and only have maxcol44, then you must list the columns:

select 
  column1, 
  column2, 
  ...
  column43, 
  (select max(column44) from zz) as maxcol44,
  column45, 
  ...
from zz;


来源:https://stackoverflow.com/questions/39611982/select-aggregate-function-and-all-other-columns

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