| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Jun 2005
Posts: 518
![]() ![]() | |
| | |
| | #2 (permalink) |
| Senior Member Join Date: May 2009 Location: internet@ctivist.com
Posts: 4,790
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | If it's a word Profit / Loss then this selects all the Profit and all the Loss that aren't profit. There are other ways to do this.. this is one. Select Time, Date, Name, Result FROM TABLE WHERE RESULT = ‘Profit’ UNION Select Time, Date, Name, Result FROM TABLE A WHERE Result = ‘Loss’ AND NOT EXISTS (Select 1 FROM TABLE B WHERE RESULT=‘Profit’ A.Date = B.Date and A.Name = B.Name)
__________________ A Member of: IdeationTeam.com HowToBeADomainer.com - a Domaining How To AuthorEditor.com
Last edited by defaultuser; 10-02-2010 at 09:21 PM.
|
| | |
| | #4 (permalink) | ||||
| Senior Member Join Date: May 2009 Location: internet@ctivist.com
Posts: 4,790
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
You have select/group by mismatch. FIND_IN_SET is a nice function but only in MySQL :-) Code: SELECT * FROM ( SELECT name, SUM(FIND_IN_SET(result, 'profit,loss')) AS P_L FROM table WHERE GROUP BY name ) AS A WHERE P_L IN (1,2)
__________________ A Member of: IdeationTeam.com HowToBeADomainer.com - a Domaining How To AuthorEditor.com | ||||
| | |
| | #5 (permalink) |
| NamePros Regular Join Date: Apr 2006
Posts: 360
![]() ![]() ![]() ![]() | I setup a test database with his info and it outputs his required return: Code: Edit Delete 13:00 01 Jan 2010 Name01 Profit Edit Delete 13:30 01 Jan 2010 Name02 Profit Edit Delete 14:30 01 Jan 2010 Name03 Loss Code: SELECT * FROM `test2` GROUP BY name ORDER BY result DESC
__________________ Canadian Domain Registrar Ready.ca |
| | |
| | #6 (permalink) | ||||
| Senior Member Join Date: May 2009 Location: internet@ctivist.com
Posts: 4,790
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
????: NamePros.com http://www.namepros.com/showthread.php?t=680193 I'm not sure if I hate or like this but I usually stick with something closer to ANSI because it might need to work in DB2/SQL Server. But I guess I learned something new today! Rep Pts 4 U | ||||
| | |