php - Use MSSQL GROUP BY with too many columns -


how can use group by location column on query having think aggregate things?

select a.[plateno] ,a.[trxdate] dates ,a.[location] ,a.[account] ,a.[trxtime] ,a.[msg] ,b.company [mark_fast].[dbo].[alarm] inner join [mark_fast].[dbo].[account] b  on a.[account] = b.senderno or a.[account] = b.sim1  a.trxdate between '09/10/2015' , '09/10/2015' , msg '%geo%'  , (a.plateno = 'bcy536') order location desc 

the sample output is:

plateno  dates    location   account   trxtime          msg             company 123     9/9/1999   loc 1      321      02:39:00  geozone exit alert!    transpartner trucking services 123     9/9/1999   loc 1      321      02:39:00  geozone exit alert!    transpartner trucking services 123     9/9/1999   loc 1      321      02:31:00  geozone entry alert!   transpartner trucking services 123     9/9/1999   loc 3      321      02:32:00  geozone exit alert!    transpartner trucking services 123     9/9/1999   loc 3      321      02:33:00  geozone exit alert!    transpartner trucking services 123     9/9/1999   loc 1      321      02:34:00  geozone entry alert!   transpartner trucking services 123     9/9/1999   loc 2      321      02:35:00  geozone exit alert!    transpartner trucking services 123     9/9/1999   loc 2      321      02:37:00  geozone entry alert!   transpartner trucking services 

i want output group location don't know how execute in query. trying achieve have output looks this:

plateno  dates    location   account   trxtime          msg             company         123     9/9/1999   loc 1      321      02:39:00  geozone exit alert!    transpartner trucking services         123     9/9/1999   loc 2      321      02:39:00  geozone exit alert!    transpartner trucking services         123     9/9/1999   loc 3      321      02:31:00  geozone exit alert! transpartner trucking services 

if want see aggregate of accounts group location you'll have add following query.

group a.location having sum(a.accounts) 

if can give sample of expected output column heads may better answer.

for latest trxtime need add following lines query

group a.location having max(a.trxtime) 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -