mirror of
https://github.com/dbgate/dbgate
synced 2024-11-08 04:35:58 +00:00
group by fix
This commit is contained in:
parent
e1eb8ffd56
commit
9cd2e68f0b
@ -16,7 +16,7 @@ export interface GridReferenceDefinition {
|
|||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GroupFunc = 'GROUP' | 'MAX' | 'MIN' | 'SUM' | 'AVG' | 'COUNT' | 'COUNT DISTINCT'
|
export type GroupFunc = 'GROUP' | 'MAX' | 'MIN' | 'SUM' | 'AVG' | 'COUNT' | 'COUNT DISTINCT' | 'NULL';
|
||||||
|
|
||||||
export interface GridConfig extends GridConfigColumns {
|
export interface GridConfig extends GridConfigColumns {
|
||||||
filters: { [uniqueName: string]: string };
|
filters: { [uniqueName: string]: string };
|
||||||
|
@ -5,7 +5,7 @@ import { parseFilter, getFilterType } from '@dbgate/filterparser';
|
|||||||
import { filterName } from './filterName';
|
import { filterName } from './filterName';
|
||||||
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
|
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
|
||||||
import { Expression, Select, treeToSql, dumpSqlSelect } from '@dbgate/sqltree';
|
import { Expression, Select, treeToSql, dumpSqlSelect } from '@dbgate/sqltree';
|
||||||
import { group } from 'console';
|
import { isTypeLogical } from '@dbgate/tools';
|
||||||
|
|
||||||
export interface DisplayColumn {
|
export interface DisplayColumn {
|
||||||
schemaName: string;
|
schemaName: string;
|
||||||
@ -206,6 +206,9 @@ export abstract class GridDisplay {
|
|||||||
const uniqueName = select.columns[i].alias;
|
const uniqueName = select.columns[i].alias;
|
||||||
if (groupColumns && groupColumns.includes(uniqueName)) continue;
|
if (groupColumns && groupColumns.includes(uniqueName)) continue;
|
||||||
const grouping = this.getGrouping(uniqueName);
|
const grouping = this.getGrouping(uniqueName);
|
||||||
|
if (grouping == 'NULL') {
|
||||||
|
select.columns[i].alias = null;
|
||||||
|
} else {
|
||||||
let func = 'MAX';
|
let func = 'MAX';
|
||||||
let argsPrefix = '';
|
let argsPrefix = '';
|
||||||
if (grouping) {
|
if (grouping) {
|
||||||
@ -224,6 +227,7 @@ export abstract class GridDisplay {
|
|||||||
args: [select.columns[i]],
|
args: [select.columns[i]],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
select.columns = select.columns.filter((x) => x.alias);
|
select.columns = select.columns.filter((x) => x.alias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -284,6 +288,7 @@ export abstract class GridDisplay {
|
|||||||
if (this.isGrouped) {
|
if (this.isGrouped) {
|
||||||
if (this.config.grouping[uniqueName]) return this.config.grouping[uniqueName];
|
if (this.config.grouping[uniqueName]) return this.config.grouping[uniqueName];
|
||||||
const column = this.baseTable.columns.find((x) => x.columnName == uniqueName);
|
const column = this.baseTable.columns.find((x) => x.columnName == uniqueName);
|
||||||
|
if (isTypeLogical(column?.dataType)) return 'COUNT DISTINCT';
|
||||||
if (column?.autoIncrement) return 'COUNT';
|
if (column?.autoIncrement) return 'COUNT';
|
||||||
return 'MAX';
|
return 'MAX';
|
||||||
}
|
}
|
||||||
@ -405,7 +410,25 @@ export abstract class GridDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getCountQuery() {
|
getCountQuery() {
|
||||||
const select = this.createSelect();
|
let select = this.createSelect();
|
||||||
|
select.orderBy = null;
|
||||||
|
|
||||||
|
if (this.isGrouped) {
|
||||||
|
select = {
|
||||||
|
commandType: 'select',
|
||||||
|
from: {
|
||||||
|
subQuery: select,
|
||||||
|
alias: 'subq',
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
exprType: 'raw',
|
||||||
|
sql: 'COUNT(*)',
|
||||||
|
alias: 'count',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
select.columns = [
|
select.columns = [
|
||||||
{
|
{
|
||||||
exprType: 'raw',
|
exprType: 'raw',
|
||||||
@ -413,7 +436,7 @@ export abstract class GridDisplay {
|
|||||||
alias: 'count',
|
alias: 'count',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
select.orderBy = null;
|
}
|
||||||
const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
||||||
return sql;
|
return sql;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,9 @@ export default function ColumnHeaderControl({ column, setSort, onResize, order,
|
|||||||
return (
|
return (
|
||||||
<HeaderDiv>
|
<HeaderDiv>
|
||||||
<LabelDiv>
|
<LabelDiv>
|
||||||
{grouping && <GroupingLabel>{grouping.toLowerCase()}:</GroupingLabel>}
|
{grouping && (
|
||||||
|
<GroupingLabel>{grouping == 'COUNT DISTINCT' ? 'distinct' : grouping.toLowerCase()}:</GroupingLabel>
|
||||||
|
)}
|
||||||
|
|
||||||
<ColumnLabel {...column} />
|
<ColumnLabel {...column} />
|
||||||
{order == 'ASC' && (
|
{order == 'ASC' && (
|
||||||
|
Loading…
Reference in New Issue
Block a user