sql group by 报错
来源:百度知道 编辑:UC知道 时间:2024/04/29 01:24:10
2个表,分别如下:
CREATE TABLE ScannerLocationMapping (
ScannerID number not null,
locationdescription varchar(150),
locationType varchar(20),
owner references CompanyDetails(Company_name),
PRIMARY KEY (ScannerID)
);
CREATE TABLE RFIDScans (
ScanNumber number not null,
timescanned TimeStamp,
businessevent varchar(100),
epc references Items(epc),
ScannerID references ScannerLocationMapping(ScannerID),
PRIMARY KEY (ScanNumber)
);
SQL语句如下:
String query="select locationType,ScanNumber,to_char(timescanned,'dd/mm/yyyy') as timescanned,businessevent,epc,rfidscans.ScannerID,count(*) from rfidscans,ScannerLocationMapping where rfidscans.scannerID=ScannerLocationMapping.scannerID AND locationtype='"+locationtype+"' and timescanned>=to_timestamp('"+timestart+"', 'DD/MM/YYYY') and timescanned<=to_timestamp('"+timeend+&q
CREATE TABLE ScannerLocationMapping (
ScannerID number not null,
locationdescription varchar(150),
locationType varchar(20),
owner references CompanyDetails(Company_name),
PRIMARY KEY (ScannerID)
);
CREATE TABLE RFIDScans (
ScanNumber number not null,
timescanned TimeStamp,
businessevent varchar(100),
epc references Items(epc),
ScannerID references ScannerLocationMapping(ScannerID),
PRIMARY KEY (ScanNumber)
);
SQL语句如下:
String query="select locationType,ScanNumber,to_char(timescanned,'dd/mm/yyyy') as timescanned,businessevent,epc,rfidscans.ScannerID,count(*) from rfidscans,ScannerLocationMapping where rfidscans.scannerID=ScannerLocationMapping.scannerID AND locationtype='"+locationtype+"' and timescanned>=to_timestamp('"+timestart+"', 'DD/MM/YYYY') and timescanned<=to_timestamp('"+timeend+&q
group by locationType,ScanNumber,timescanned,businessevent,epc,rfidscans.ScannerID
group by epc 应改为:
group by locationType,ScanNumber,to_char(timescanned,'dd/mm/yyyy') as timescanned,businessevent,epc,rfidscans.ScannerID
也就是说除了count(*)之外的,你要照搬下来。
除了count(*)这个统计字段之外
你所有的显示字段都应该放在group by 的后面
group by a
那么在select 后面一切非a的都要运算一下
字符的也要max()一下。