排除SELECT語句的列組我有一個生成一個報告by子句
select
cust.firstname as "FIRST NAME",
cust.lastname as "LAST NAME",
dept.name as "DEPARTMENT",
subdept.name as "SUB DEPARTMENT",
count(*) "cust type"
from cust
join dept on dept.deptid = cust.deptid
join subdept on subdept.deptid = cust.subdeptid
join custactivity on custactivity.custid = cust.custid
where custactivity.swipetime > (trunc(sysdate - 1))
group by cust.firstname,cust.lastname,dept.name,subdept.name
having count(*) > 5
order by "DEPARTMENT" ;
現在下面的查詢,我想包括列「custactivity.swipetime」只有在SELECT語句,但沒有組by子句,因爲它是一個時間字段,如果將它包含在group by子句中,我會得到不正確的結果。這可能怎麼樣?
我試過在ORACLE Select and group by excluding one field 的解決方案,但它沒有解決。
任何人都可以幫忙嗎?
您希望爲這個非分組列的哪個值?如果這個值不是唯一的,那麼你可以分組。如果它有多個值,你會期望哪一個? – Grayson
你在問Oracle還是PostgreSQL? PL/SQL如何處理?不要標記不涉及的產品和語言。 –
我刪除了Postgres和PL/SQL標記,因爲這顯然是Oracle的一個SQL唯一問題 –