4 Replies - 307 Views - Last Post: 05 April 2013 - 11:43 AM Rate Topic: -----

#1 Jay0830  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 58
  • Joined: 01-June 10

Quest problem: group by

Posted 05 April 2013 - 10:08 AM

I have a database like this:

ID path user type
---------------------
1 1.jpg 20 photo
2 2.jpg 5 photo
3 3.jpg 50 image
4 4.jpg 45 image

The result that after grouping I want is:

ID path user type
---------------------
1 1.jpg 20 photo
3 3.jpg 50 image
4 4.jpg 45 image

How to group only if type equal photo?

Thanks for help

Is This A Good Question/Topic? 0
  • +

Replies To: Quest problem: group by

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9381
  • View blog
  • Posts: 35,228
  • Joined: 12-June 08

Re: Quest problem: group by

Posted 05 April 2013 - 10:14 AM

I'm not following.. what does that 'after grouping' supposed to mean? Why those three rows and not the #2?

What, exactly, is the rules you want for that 'after grouping'? It doesn't make sense why those three are there and not line #2.
Was This Post Helpful? 0
  • +
  • -

#3 Jay0830  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 58
  • Joined: 01-June 10

Re: Quest problem: group by

Posted 05 April 2013 - 10:58 AM

modi123_1 thanks for your quick reply

ID path user type
---------------------
1 1.jpg 20 photo
2 2.jpg 5 photo
3 3.jpg 50 image
4 4.jpg 45 image

The Query: SELECT * FROM data GROUP BY type

the result would be
ID path user type
---------------------
1 1.jpg 20 photo
3 3.jpg 50 image

right?

but I want the "GROUP BY" only work in type='photo', become:


ID path user type
---------------------
1 1.jpg 20 photo
3 3.jpg 50 image
4 4.jpg 45 image

only type=photo process "GROUP BY" this command.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9381
  • View blog
  • Posts: 35,228
  • Joined: 12-June 08

Re: Quest problem: group by

Posted 05 April 2013 - 11:20 AM

But in that example you have multiple types of 'image'.. what's up with that?
Was This Post Helpful? 0
  • +
  • -

#5 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,692
  • Joined: 13-March 10

Re: Quest problem: group by

Posted 05 April 2013 - 11:43 AM

You should check out what GROUP BY is used for. It's for summarizing data. You cannot apply it partially.

SELECT type, other_columns
FROM ____
GROUP BY type

now, if you want other_columns, use aggregate functions and they will be applied to each group.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1