php - SELECT DISTINCT with field type 'text' and SUM(amt) -
i'm having trouble sql query:
this i'm trying do:
"select distinct *, sum(amt) ttl_amt table where..."
two of fields of type 'text', sql not allow type selected distinct not comparable.
i need group relative items , display them single row combined ttl_amt
value seen above.
i've tried selecting 'non-text' fields (varchar, float, int, etc) in select distinct
statement , pulling 'text' fields in while()
loop using sql query information not show (the 'text' fields).
if need more information let me know.
any ideas? i'm not expert when comes sql syntax.
when using aggregate functions sum()
, count()
, avg()
etc. outher fields within select
section should either within aggregate functions or should mentioned in group by
. seems want sql being that:
select field1, -- can't use * here! field2, ... fieldn, sum(amt) table group field1, -- can't use * here! field2, ... fieldn
group by
makes grouping distinct, don't need additional distinct
here
Comments
Post a Comment