Re: Mysql 5.1 union with group by for results

2013-11-08 Thread Machiel Richards
) FROM t1 t) UNION (SELECT t.id, t.name, SUM(val) FROM t2 t) GROUP BY t.id, t.name; That does not work in 5.0 either (at least in 5.0.96): ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax

Re: Mysql 5.1 union with group by for results

2013-11-08 Thread Machiel Richards
or in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY t.AccountID, I suspect your query has never been doing what you think at all, and you need to select [fields] from ( select fields1 blahblah UN

Re: Mysql 5.1 union with group by for results

2013-11-08 Thread Johan De Meersman
- Original Message - > From: "Machiel Richards" > > ERROR 1064 (42000): You have an error in your SQL syntax; check the > manual that corresponds to your MySQL server version for the right > syntax to use near 'GROUP BY t.AccountID, I suspect your query

Re: Mysql 5.1 union with group by for results

2013-11-08 Thread Jesper Wisborg Krogh
shorter but equivalent query, you have: (SELECT t.id, t.name, SUM(val) FROM t1 t) UNION (SELECT t.id, t.name, SUM(val) FROM t2 t) GROUP BY t.id, t.name; That does not work in 5.0 either (at least in 5.0.96): ERROR 1064 (42000): You have an error in your SQL syntax; check the

Mysql 5.1 union with group by for results

2013-11-08 Thread Machiel Richards
=a.ID LEFT JOIN client2 c ON t.ClientID=c.ID LEFT JOIN tocname tc ON t.TOC=tc.toc LEFT JOIN network n ON t.NetworkID=n.ID WHERE t.toc=1 AND SUBSTRING(t.Day,1,7) >= '2013-08' AND SUBSTRING(t.Day,1,7) <= '2013-11') GROUP BY t.AccountID,

Re: getting certain rows from a group by

2012-09-20 Thread Larry Martell
On Wed, Sep 19, 2012 at 6:56 PM, Rick James wrote: >> my counts are 3 times too much. > Without studying the code, I would guess that there is a JOIN between he data > that needs COUNTing and the GROUP BY for the COUNT. That is, it collects > more 'joined' rows before

Re: getting certain rows from a group by

2012-09-19 Thread hsv
2012/09/19 14:36 -0400, Larry Martell MIN(ABS(Avg(bottom) - bottom)) Is not valid. It gives: ERROR (HY000): Invalid use of group function Yes, I had my doubts of that, for all that I suggested it. -- MySQL General Mailing List For list archives: http://lists.mysql.com/m

RE: getting certain rows from a group by

2012-09-19 Thread Rick James
> my counts are 3 times too much. Without studying the code, I would guess that there is a JOIN between he data that needs COUNTing and the GROUP BY for the COUNT. That is, it collects more 'joined' rows before counting. Fixing it will probably make the query even messier. &g

Re: getting certain rows from a group by

2012-09-19 Thread Larry Martell
ottom) as Ranges FROM data_cst WHERE TRUE AND data_cst.target_name_id IN (775, 776, 777, 778, 779, 780, 45, 44, 116, 117, 118, 119, 120, 121) AND data_cst.date_time BETWEEN '2010-03-04 00:00:00' AND '2010-0

Re: getting certain rows from a group by

2012-09-19 Thread Larry Martell
OK, I think I have this working. The last join was this: JOIN (select id, target_name_id, ep,date_time from data_cst WHERE target_name_id IN (775, 776, 777, 778, 779, 780, 45, 44, 116, 117, 118, 119, 120, 121) AND data_cst.date_time BETWEEN '2010-03-04 00:00:00' AND '2010-03-04 23:

Re: getting certain rows from a group by

2012-09-19 Thread Larry Martell
- >> bottom)) AS vb, Max(date_time) AS xt >> FROM data_cst >> WHERE target_name_id IN (775, 776, 777, 778, 779, 780, 45, 44, 116, >> 117, 118, 119, 120, 121) >> AND DATE(data_cst.date_time) = '2010-03-04' >> GROUP BY target_name_id,

Re: getting certain rows from a group by

2012-09-19 Thread Larry Martell
d IN (775, 776, 777, 778, 779, 780, 45, 44, 116, > 117, 118, 119, 120, 121) > AND DATE(data_cst.date_time) = '2010-03-04' > GROUP BY target_name_id, ep, wafer_id > HAVING count(*) < 999) AS st > JOIN data_cst ON st.target_name_id = data_cst.target_name_id AND (nb =

Re: getting certain rows from a group by

2012-09-19 Thread Larry Martell
d IN (775, 776, 777, 778, 779, 780, 45, 44, 116, > 117, 118, 119, 120, 121) > AND DATE(data_cst.date_time) = '2010-03-04' > GROUP BY target_name_id, ep, wafer_id > HAVING count(*) < 999) AS st > JOIN data_cst ON st.target_name_id = data_cst.target_name_id AND (n

Re: getting certain rows from a group by

2012-09-19 Thread Larry Martell
-04 00:00:00' AND '2010-03-04 > 23:59:59' > AND data_target.id = data_cst.target_name_id > GROUP BY rollup.Target, rollup.EP > ORDER BY ABS(data_cst.bottom - rollup.`Avg Bottom`) > LIMIT 1 -- <-- rollup is the name of the temp

Re: getting certain rows from a group by

2012-09-18 Thread hsv
b, vb, xt, bottom FROM (SELECT Min(bottom) AS nb, Max(bottom) AS xb, MIN(ABS(Avg(bottom) - bottom)) AS vb, Max(date_time) AS xt FROM data_cst WHERE target_name_id IN (775, 776, 777, 778, 779, 780, 45, 44, 116, 117, 118, 119, 120, 121) AND DATE(data_cst.date_time) = '20

RE: getting certain rows from a group by

2012-09-18 Thread Rick James
AND data_target.id = data_cst.target_name_id GROUP BY rollup.Target, rollup.EP ORDER BY ABS(data_cst.bottom - rollup.`Avg Bottom`) LIMIT 1 -- <-- > -Original Message- > From: Larry Martell [mailto:larry.mart...@gmail.com] > Sent: Tuesday, September 18, 2012 2:57 P

Re: getting certain rows from a group by

2012-09-18 Thread Larry Martell
ta_target WHERE data_target.name = rollup.Target AND data_cst.ep = rollup.EP AND data_cst.date_time BETWEEN '2010-03-04 00:00:00' AND '2010-03-04 23:59:59' AND data_target.id = data_cst.target_name_id GROUP BY rollup.Target, rollup.EP ORDER BY ABS(data_cst.bottom - rollup.`Avg Bot

RE: getting certain rows from a group by

2012-09-18 Thread Rick James
com > Subject: Re: getting certain rows from a group by > > On Tue, Sep 18, 2012 at 2:05 PM, Rick James > wrote: > > For single query... > > > > Plan A: > > Repeat the SELECT as once for each (MIN, AVG, etc) as a subquery in > >WHERE bottom =

Re: getting certain rows from a group by

2012-09-18 Thread Larry Martell
ail.com] >> Sent: Tuesday, September 18, 2012 4:57 AM >> To: peter.braw...@earthlink.net >> Cc: mysql@lists.mysql.com >> Subject: Re: getting certain rows from a group by >> >> On Tue, Sep 18, 2012 at 7:52 AM, Peter Brawley >> wrote: >> > On

Re: getting certain rows from a group by

2012-09-18 Thread Larry Martell
MAX(date_time) as "LastRun", >>> COUNT(*) as numonep, >>> COUNT(DISTINCT target_name_id, ep, lot_id, >>> data_file_id)-1 as reruns, >>> COUNT(DISTINCT(lot_id)) as Lots, >>> 3*STD(bottom)

RE: getting certain rows from a group by

2012-09-18 Thread Rick James
Cc: mysql@lists.mysql.com > Subject: Re: getting certain rows from a group by > > On Tue, Sep 18, 2012 at 7:52 AM, Peter Brawley > wrote: > > On 2012-09-18 5:53 AM, Larry Martell wrote: > >> > >> I have this query: > >> > >> SELECT data_t

Re: getting certain rows from a group by

2012-09-18 Thread Larry Martell
maxbottom, >> MIN(bottom) as minbottom, >> MAX(date_time) as "LastRun", >> COUNT(*) as numonep, >> COUNT(DISTINCT target_name_id, ep, lot_id, >> data_file_id)-1 as reruns, >> COUN

Re: getting certain rows from a group by

2012-09-18 Thread Peter Brawley
OM data_cst WHERE target_name_id IN (775, 776, 777, 778, 779, 780, 45, 44, 116, 117, 118, 119, 120, 121) AND data_cst.date_time BETWEEN '2010-03-04 00:00:00' AND '2010-03-04 23:59:59' GROUP BY target_name_id, ep, wafer_id HAVING count(*) < 999)

getting certain rows from a group by

2012-09-18 Thread Larry Martell
COUNT(DISTINCT target_name_id, ep, lot_id, data_file_id)-1 as reruns, COUNT(DISTINCT(lot_id)) as Lots, 3*STD(bottom) as Wafer3Sigma, MAX(bottom) - MIN(bottom) as Ranges FROM data_cst WHERE target_name_id IN (775, 776, 777, 778, 779, 780, 45, 44,

Re: strange select/join/group by with rollup issue....

2012-02-08 Thread Andy Wallace
Thanks, it seems to be working now. I just discovered "WITH ROLLUP". It made me very happy on this project... On 2/8/12 2:54 AM, Arthur Fuller wrote: I'm not sure your method isn't working, but try changing changing the "to date" part to "< '2012-02-08' " and see what you get. HTH, Arthur

Re: strange select/join/group by with rollup issue....

2012-02-08 Thread Arthur Fuller
I'm not sure your method isn't working, but try changing changing the "to date" part to "< '2012-02-08' " and see what you get. HTH, Arthur

strange select/join/group by with rollup issue....

2012-02-07 Thread Andy Wallace
I am having a problem with select results that I don't understand. It seems to be tied up with a GROUP BY statement. Forgive the complexity of the SQL, I inherited some problematic data structuring. If I use this statement: SELECT lu_rcode_bucket.bucket AS 'BUCKET',

Partial Index with group by

2011-06-06 Thread Les Fletcher
I am trying to optimize a query that uses a group by on a varchar(255) column. The column has a large enough cardinality that a 10 character partial index uniquely covers over 99% of all values. I was hoping that this partial index would be able to help with the group by (though obviously not as

RE: Group By Problem

2011-02-08 Thread Peter He
You need to group by event_text, not obj_text: select source_id ,event_text,count(*) from event_loc group by source_id,event_text; > Date: Tue, 8 Feb 2011 16:31:39 +0530 > From: adarsh.sha...@orkash.com > To: mysql@lists.mysql.com > Subject: Group By Problem > > Dear

Group By Problem

2011-02-08 Thread Adarsh Sharma
3 performs 1 13456 Minister 1 I tried the below query : *select source_id ,event_text,count(*) from event_loc group by source_id,obj_text ;* But displays only unique record_id rows but I want as

Re: Group by question

2011-01-20 Thread dan
11:18:58 | 2011-01-16 11:13:04 | +--+-+-+ 8 rows in set (0.09 sec) The problem is that album_id 81 is occuring two times in the list. So I thought I should add a "group by" in the query: mysql> select album_id, updated_at, created_at

Re: Group by question

2011-01-17 Thread Luciano Furtado
gt; mysql> select album_id, updated_at, created_at from album_stats group by >>> album_id order by updated_at desc limit 8; >> >> I believe that your problem is that the group by happens before the >> order by. Since you're grouping, the updated_at column is not >&

Re: Group by question

2011-01-17 Thread Jørn Dahl-Stamnes
On Monday 17 January 2011 09:53, Steve Meyers wrote: > On 1/16/11 5:22 AM, Jørn Dahl-Stamnes wrote: > > mysql> select album_id, updated_at, created_at from album_stats group by > > album_id order by updated_at desc limit 8; > > I believe that your problem is that the gro

Re: Group by question

2011-01-17 Thread Steve Meyers
On 1/16/11 5:22 AM, Jørn Dahl-Stamnes wrote: mysql> select album_id, updated_at, created_at from album_stats group by album_id order by updated_at desc limit 8; I believe that your problem is that the group by happens before the order by. Since you're grouping, the updated_at colum

Group by question

2011-01-16 Thread Jørn Dahl-Stamnes
:04 | +--+-+-+ 8 rows in set (0.09 sec) The problem is that album_id 81 is occuring two times in the list. So I thought I should add a "group by" in the query: mysql> select album_id, updated_at, created_at from album_stats group by album_id order by

Re: Query Stored Index instead of Group By

2010-12-20 Thread Feris Thia
Hi Johan, On Sun, Dec 19, 2010 at 7:11 PM, Johan De Meersman wrote: > You can't query the index directly, but if you select only fields that are > in the index, no table lookups will be performed - this is called a covering > index. > Great.. Thanks for the confirmation. Regards, Feris > > -

Re: Query Stored Index instead of Group By

2010-12-19 Thread Johan De Meersman
On Sun, Dec 19, 2010 at 3:19 AM, Feris Thia < milis.datab...@phi-integration.com> wrote: > Hi Everyone, > > Is there a way to query values stored in our index instead of using "group > by" selection which will produce same results ? > You can't query the in

Query Stored Index instead of Group By

2010-12-18 Thread Feris Thia
Hi Everyone, Is there a way to query values stored in our index instead of using "group by" selection which will produce same results ? Please advice.. Regards, Feris

GROUP BY - INNER JOIN and LIMIT - how to get result

2010-11-29 Thread Arkadiusz Malka
I have tables: CREATE TABLE `tblNames` ( ` IdName` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(60) DEFAULT NULL, PRIMARY KEY (`IdName`), ) ENGINE=MyISAM CREATE TABLE `tblStatusy` ( `IdStatus` int(11) NOT NULL AUTO_INCREMENT, `IdName` int(11) DEFAULT NULL, `Status`

RE: concatenate sql query with group by and having

2010-07-29 Thread Travis Ard
where geneName in -- returns all geneNames (symbols) with one unique combination of chrom and strand (select geneName from -- returns all unique combinations of symbol, chrom, and strand (select distinct geneName, chrom, strand from refFlat) sub1 group by geneName having count(*) = 1) group b

concatenate sql query with group by and having

2010-07-28 Thread Peng Yu
symbols but different chrom and strand). Could anybody show me how to do it? select geneName as symbol, name as refSeq, chrom, strand, txStart from refFlat group by refSeq having count(*)=1; I think that something like SELECT name FROM (SELECT name, type_id FROM (SELECT * FROM foods)); works

Re: Select w/ group by question

2010-07-14 Thread Scott Mullen
UBSTR( MIN( CONCAT( LPAD(price,6,0),supplier) ), 7) AS MinSupplier, LEFT( MIN( CONCAT( LPAD(price,6,0),supplier) ), 6)+0 AS MinPrice, SUBSTR( MAX( CONCAT( LPAD(price,6,0),supplier) ), 7) AS MaxSupplier, LEFT( MAX( CONCAT( LPAD(price,6,0),supplier) ), 6)+0 AS MaxPrice FROM products GRO

RE: Select w/ group by question

2010-07-14 Thread Martin Gainty
> Date: Wed, 14 Jul 2010 10:25:22 -0400 > Subject: Select w/ group by question > From: smulle...@gmail.com > To: mysql@lists.mysql.com > > I'm having trouble formulating a query to gather the following data. I can > do this via a script, but now it is more or

Re: Select w/ group by question

2010-07-14 Thread Michael Satterwhite
Walmart > (Note: both vendors 1 and 3 have the same cost which is the lowest. I'm > not really concerned with which vendor is chosen in the result set here.) > > Try this: select name, product_type, min(cost) from vendors join products on vendors.id =

Re: Select w/ group by question

2010-07-14 Thread Peter Brawley
= b.vendor_id group by a.type, a.vendor_id, b.vendor_name all rows are returned because the type/vendor_id/vendor_name are unique amongst each row. If you remove the vendor_id and vendor_name from the group by, you get a single row with the lowest cost for each product, but the vendor_id

Select w/ group by question

2010-07-14 Thread Scott Mullen
_name from products a join vendors b on a.vendor_id = b.vendor_id group by a.type, a.vendor_id, b.vendor_name all rows are returned because the type/vendor_id/vendor_name are unique amongst each row. If you remove the vendor_id and vendor_name from the group by, you get a single row with the lowes

Re: Duplicate entries despite group by

2010-02-21 Thread Carsten Pedersen
NULL, `weight` int(10) NOT NULL, PRIMARY KEY (`tableid1`,`tupleid1`,`tableid2`,`tupleid2`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 and I'm running this query (note the 'group by'): insert into graph (node1, node2, tableid1, tupleid1, tableid2, tupleid2, weight)

Duplicate entries despite group by

2010-02-20 Thread Yang Zhang
`,`tupleid1`,`tableid2`,`tupleid2`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 and I'm running this query (note the 'group by'): insert into graph (node1, node2, tableid1, tupleid1, tableid2, tupleid2, weight) select 0, 0, a.tableid, a.tupleid, b.tableid, b.tupleid, count(

Re: help with group by

2009-10-28 Thread Adam Williams
works perfectly, i didn't know you could use multiple columns in the group by. thanks a bunch! Michael Dykman wrote: try this: select accepted_by, problem_type, count(*) from form where problem_type is not NULL AND problem_type != 'Test' AND accepted_by is not null group

Re: help with group by

2009-10-28 Thread Michael Dykman
try this: select accepted_by, problem_type, count(*) from form where problem_type is not NULL AND problem_type != 'Test' AND accepted_by is not null group by accepted_by, problem_type On Wed, Oct 28, 2009 at 12:05 PM, Adam Williams wrote: > I've written a helpdesk ticket prob

help with group by

2009-10-28 Thread Adam Williams
I've written a helpdesk ticket problem and am working on the statistics module. I'm having problems with group by. For instance, I want to get the count of the number of different problem types, by how many were solved by each person. This is my statement: mysql> se

Performance tuning a group by with percentage

2009-10-16 Thread Scott Haneda
) AS thecount, COUNT( * ) / ( SELECT COUNT( * ) FROM agents ) AS percentage FROM agents GROUP BY user_agent_parsed ORDER BY thecount DESC LIMIT 50; Second issue, once a day I need to archive the result of the above. Any suggestions on how to best to do that? I can schedule with cron, or in

RE: Stupid GROUP BY question

2009-09-25 Thread Gavin Towey
nt: Friday, September 25, 2009 1:28 PM To: mysql@lists.mysql.com Subject: Stupid GROUP BY question It must be too late in the week… Suppose table Cust has one field, CustID. Suppose table Notes has four fields: NoteID (unique), CustID, NoteTime, and NoteText. A customer can have zero or more

Re: Stupid GROUP BY question

2009-09-25 Thread Peter Brawley
stomer. If all I want is the date, then I can do SELECT Cust.CustID, MAX(Notes.NoteTime) FROM Cust LEFT JOIN Notes ON Cust.CustID = Notes.Cust_ID GROUP BY Cust.CustID; That will work just fine, but now I also want the NoteText associated with the newest note. Obviously I can'

Stupid GROUP BY question

2009-09-25 Thread Jerry Schwartz
newest note (if any) for each customer. If all I want is the date, then I can do SELECT Cust.CustID, MAX(Notes.NoteTime) FROM Cust LEFT JOIN Notes ON Cust.CustID = Notes.Cust_ID GROUP BY Cust.CustID; That will work just fine, but now I also want the NoteText associated with the newest

Re: Group by optimization

2009-08-16 Thread Suhail Doshi
Peter, I am fairly certain, it's not slow because of the event_id look up but because of the GROUP BY Suhail On Sun, Aug 16, 2009 at 2:56 PM, Peter Brawley wrote: > Suhail, > > Having problems with this query, any ideas on how to optimize this further? > > Did you try writ

Re: Group by optimization

2009-08-16 Thread Peter Brawley
6,105689,105909,106173,106311,106459,107118,107320,107662,107970,108155,108379,108418,108618,108779,108960,109506,109691,110067,110469,110698,110806,111201,111286,111641,112174,112375,112568,112656,113094,113248,113344,113449,113561,113909,114170,114322,114432,115059,115146,115244,115541,115689,116305,116405,116762,117148,117296,117389,117504,117779,117945,118285,118447,118571,118752) G

Group by optimization

2009-08-16 Thread Suhail Doshi
2,115059,115146,115244,115541,115689,116305,116405,116762,117148,117296,117389,117504,117779,117945,118285,118447,118571,118752) GROUP BY cache_property_str.name ORDER BY NULL LIMIT

RE: Group by column and Sum another

2009-07-20 Thread Hagen
Thanks! That did the trick. -Original Message- From: Olexandr Melnyk [mailto:omel...@gmail.com] Sent: Monday, July 20, 2009 10:02 AM To: mysql@lists.mysql.com Subject: Re: Group by column and Sum another select contract , sum(amlp) from maintenance group by contract; On Mon, Jul 20

Re: Group by column and Sum another

2009-07-20 Thread Olexandr Melnyk
select contract , sum(amlp) from maintenance group by contract; On Mon, Jul 20, 2009 at 6:50 PM, Hagen wrote: > I am hoping I can get some help with a query I am trying to construct: > > I want to group by a 'contract' column and get the sum of the 'amlp' co

Group by column and Sum another

2009-07-20 Thread Hagen
I am hoping I can get some help with a query I am trying to construct: I want to group by a 'contract' column and get the sum of the 'amlp' column values associated with each contract. I can do a select and group by on contract select contract from maintenance group by contr

Using RANDOM before GROUP BY technique returned only a single column

2009-07-06 Thread Highviews
Hi, I am using a technique described here at: http://forums.mysql.com/read.php?20,227102,227102#msg-227102 To make results Random before applying the GROUP BY method. The query to my table structure is this: SELECT r.physicians_id, (SELECT r1.id FROM physicians_images r1 WHERE (r.physicians_id

RE: group by different time period than functions allow

2009-06-11 Thread Rolando Edwards
ate < B.DT2 group by week(A.mydate); Give this one a Try !!! Rolando A. Edwards MySQL DBA (CMDBA) 155 Avenue of the Americas, Fifth Floor New York, NY 10013 212-625-5307 (Work) 201-660-3221 (Cell) AIM & Skype : RolandoLogicWorx redwa...@logicworks.net -Original Message- From: Rolan

RE: group by different time period than functions allow

2009-06-11 Thread Rolando Edwards
) DT2 FROM (SELECT DATE_ADD(DATE(DATE_ADD(NOW(),INTERVAL (DOW-DAYOFWEEK(NOW())) DAY)),INTERVAL HR HOUR) DT FROM (SELECT 4 DOW, 9 HR) AA) AAA) B Where A.mydate >= B. DT1_9AM And A.mydate < B. DT2_9AM group by week(A.mydate); Give it a Try !!! Rolando A. Edwards MySQL DBA (CMDBA) 155 Avenue

group by different time period than functions allow

2009-06-11 Thread Andrey Dmitriev
Can someone point a link, or show an example. basically, i have something like select week(mydate), count(mystuff) from table group by week(mydate); however, I need week to start on Wed 9am and end next Wed. What's the easiest way to accomplish that? thanks, andrey -- MySQL General Ma

Re: displaying a specific row within a "group by"

2009-04-09 Thread Olexandr Melnyk
;> >> ++--+--+ >> | game   | rank | date     | >> ++--+--+ >> | SPORE  |  50  | 20090402 | >> ++--+--+ >> | SINSOL |  11  | 20090104 | >> ++--+--+ >> | GTA    |  21  

Re: displaying a specific row within a "group by"

2009-04-09 Thread Peter Brawley
+ | SINSOL | 11 | 20090104 | ++--+--+ | GTA| 21 | 20080821 | ++--+--+ | WOW| 15 | 20090106 | ++--+--+ How do I go about it? The initial 'obvious' solution: select game,rank,max(date) from gametbl group by game DOES

displaying a specific row within a "group by"

2009-04-09 Thread Andy Sy
vious' solution: select game,rank,max(date) from gametbl group by game DOESN'T work because the 'rank' value we get will not necessarily come from the same row holding the 'max(date)'!! Instead, you have to sort by date first in a subquery before applying the GROU

Re: Group by question

2009-01-07 Thread Niteen Acharya
Hello, I think following query would help you For Ascending select cpid,sum(score),team from j group by cpid order by sum(score) For Descending select cpid,sum(score),team from j group by cpid order by sum(score) desc Thanks! 2009/1/7 Phil > A question on grouping I've never been

Re: Group by question

2009-01-07 Thread Peter Brawley
|3 | 300 | a | team2 | | aaa |4 | 100 | b | team2 | | bbb |5 | 300 | b | team1 | | ccc |6 | 400 | bbbbb | team1 | | aaa |7 | 101 | c | team1 | | bbb |8 | 302 | ccc

Group by question

2009-01-07 Thread Phil
aa | team1 | | bbb |2 | 200 | a | team1 | | ccc |3 | 300 | a | team2 | | aaa |4 | 100 | b | team2 | | bbb |5 | 300 | b | team1 | | ccc |6 | 400 | b | team1 | | aaa |

Re: Can't get expected SELECT GROUP BY results

2008-12-26 Thread Fish Kungfu
| > 2008-12-2601:13:58| > |yard|dog|<110.05429, 22.43897, 43.31427>| > 2008-12-2601:14:30| > |yard|cat|<109.83472, 22.45278, 43.29317>| > 2008-12-2601:14:30| > |yard|dog|<110.05429, 22.43897,

Re: Can't get expected SELECT GROUP BY results

2008-12-26 Thread Peter Brawley
14:57| * What I want to do is SELECT only the most recent dateTime and critterXYZ for each critterName and return one row for each unique critterName. So far I have this SELECT statement: mysql> SELECT r

Re: Can't get expected SELECT GROUP BY results

2008-12-26 Thread Peter Brawley
is SELECT only the most recent dateTime and critterXYZ for each critterName and return one row for each unique critterName. So far I have this SELECT statement: mysql> SELECT regionName,cr

Can't get expected SELECT GROUP BY results

2008-12-26 Thread Fish Kungfu
o do is SELECT only the most recent dateTime and critterXYZ for each critterName and return one row for each unique critterName. So far I have this SELECT statement: mysql> SELECT regionName,critterName,crit

Re: Maintaining sort order with 'GROUP BY' and 'HAVING'

2008-12-04 Thread Andy Shellam
an someone suggest a workaround for this (other than upgrading MySQL). Thanks, Nishi CREATE TABLE t ( id TINYINT, title VARCHAR(10) ); INSERT INTO t (id, title) VALUES (1, 'aaa'), (2, 'bbb'), (3, 'ccc'), (4, 'ddd'), (5, 'eee'); (a) DO @sn := 0; S

Re: Maintaining sort order with 'GROUP BY' and 'HAVING'

2008-12-04 Thread Nishikant Kapoor
). Thanks, Nishi CREATE TABLE t ( id TINYINT, title VARCHAR(10) ); INSERT INTO t (id, title) VALUES (1, 'aaa'), (2, 'bbb'), (3, 'ccc'), (4, 'ddd'), (5, 'eee'); (a) DO @sn := 0; SELECT @sn:[EMAIL PROTECTED] sn, id, title FROM t G

Re: Maintaining sort order with 'GROUP BY' and 'HAVING'

2008-11-27 Thread Nishikant Kapoor
;aaa'), (2, 'bbb'), (3, 'ccc'), (4, 'ddd'), (5, 'eee'); (a) DO @sn := 0; SELECT @sn:[EMAIL PROTECTED] sn, id, title FROM t GROUP BY id ORDER BY id desc; | sn | id | title | +--+--+---+ |1 |5 | eee | |2 |4 | ddd |

Re: Maintaining sort order with 'GROUP BY' and 'HAVING'

2008-11-27 Thread Nishikant Kapoor
#x27;), (2, 'bbb'), (3, 'ccc'), (4, 'ddd'), (5, 'eee'); (a) DO @sn := 0; SELECT @sn:[EMAIL PROTECTED] sn, id, title FROM t GROUP BY id ORDER BY id desc; | sn | id | title | +--+--+---+ |1 |5 | eee | |2 |4 | ddd | |

Re: Maintaining sort order with 'GROUP BY' and 'HAVING'

2008-11-27 Thread Andy Shellam
Hi Nishi, There was a bug in that version that affected the sort order when combined with a group by statement (http://bugs.mysql.com/bug.php?id=32202.) There are a couple of workarounds but they are bad (e.g. removing primary key!) I would strongly suggest you upgrade to 5.0.67 or

Maintaining sort order with 'GROUP BY' and 'HAVING'

2008-11-27 Thread Nishikant Kapoor
CREATE TABLE t ( id TINYINT, title VARCHAR(10) ); INSERT INTO t (id, title) VALUES (1, 'aaa'), (2, 'bbb'), (3, 'ccc'), (4, 'ddd'), (5, 'eee'); (a) DO @sn := 0; SELECT @sn:[EMAIL PROTECTED] sn, id, title FROM t GROUP BY id ORDER BY id desc; | sn

Re: Problem with GROUP BY

2008-10-20 Thread Moon's Father
Learnt! On Wed, Oct 15, 2008 at 5:28 PM, philip <[EMAIL PROTECTED]> wrote: > > Date: Tue, 14 Oct 2008 16:55:11 +0300 > > From: Olexandr Melnyk <[EMAIL PROTECTED]> > > To: [EMAIL PROTECTED], mysql@lists.mysql.com > > Subject: Re: Problem with GROUP BY > >

Re: Problem with GROUP BY

2008-10-15 Thread philip
> Date: Tue, 14 Oct 2008 16:55:11 +0300 > From: Olexandr Melnyk <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED], mysql@lists.mysql.com > Subject: Re: Problem with GROUP BY > > http://jan.kneschke.de/projects/mysql/groupwise-max > > 2008/10/14 Peter Brawley <

Re: Problem with GROUP BY

2008-10-14 Thread Olexandr Melnyk
http://jan.kneschke.de/projects/mysql/groupwise-max 2008/10/14 Peter Brawley <[EMAIL PROTECTED]> > Philip > > mysql> SELECT number, MAX(event), name FROM info GROUP BY number; >> > > For discussion & examples see "Within-group aggregates" at > ht

Re: Problem with GROUP BY

2008-10-14 Thread Peter Brawley
Philip mysql> SELECT number, MAX(event), name FROM info GROUP BY number; For discussion & examples see "Within-group aggregates" at http://www.artfulsoftware.com/queries.php. PB - philip wrote: I created a table with, CREATE TABLE info ( number INTEGER UN

Problem with GROUP BY

2008-10-14 Thread philip
| 1 | David | | 72 | 3 | David | +++---+ The closest I have managed to produce using GROUP BY is, mysql> SELECT number, MAX(event), name FROM info GROUP BY number; +++---+ | number | MAX(event) | n

Re: Optimizing GROUP BY and ORDER BY

2008-07-25 Thread Michael Stearne
ountry != 'Unit' AND Country >> != 'United States' AND Country != ' ' AND Country IS NOT NULL ) GROUP >> BY Country ORDER BY Cnt DESC LIMIT 8 >> >> that g

Re: Optimizing GROUP BY and ORDER BY

2008-07-25 Thread Rob Wultsch
' AND > Country != 'United States' > AND Country != ' ' > AND Country IS NOT NULL ) > GROUP BY Country > ORDER BY Cnt > DESC LIMIT > > This is a costly query I suggest that this is not a well normalized. I suggest that at a min

Optimizing GROUP BY and ORDER BY

2008-07-25 Thread Michael Stearne
I have a query: SELECT Country, COUNT( Country ) AS Cnt FROM properties WHERE ( Country != 'USA' AND Country != 'US' AND Country != 'Unit' AND Country != 'United States' AND Country != ' ' AND Country IS NOT NULL ) GROUP BY Country ORDER BY Cnt

Re: trouble with group by and similar tables

2008-06-30 Thread Joerg Bruehe
able2 WHERE table1.some_field = 'value' AND table2.id1 = table1.id GROUP BY table1.id This works fine and returns each record in table1, grouped by id, with the sum of scores from table2. However, when I do this query: SELECT table1.id,SUM(table2.score) as table2_score, SUM(ta

Re: Do I need to use GROUP BY to do this?

2008-06-24 Thread Ian Simpson
Off the top of my head I can't think of a way of getting the output in the format that you want. If you use a query like: SELECT SUBSTRING(sales_date,1,10), sales_type, COUNT(sales_id) FROM sales_activity GROUP BY SUBSTRING(sales_date,1,10), sales_type; You'll get output l

Re: Error with max and group by

2008-06-21 Thread Perrin Harkins
On Sat, Jun 21, 2008 at 8:34 AM, Joe Pearl <[EMAIL PROTECTED]> wrote: > Thanks, but this is not the result I want. I really think it is. You seem to be misunderstanding how GROUP BY works. In any other database than MySQL, the SQL you wrote would simply give an error. In MySQL, it

Re: Error with max and group by

2008-06-21 Thread Brent Baisley
d out what the max date is, and then find out what record that max date belongs to so you can pull the rest of the information from that record. You can do this by use a select on a "virtual" table. First, get the max date: select name,max(acq_date) AS mx_acq_date from cust_full grou

Re: Error with max and group by

2008-06-21 Thread Joe Pearl
Thanks, but this is not the result I want. The SQL for the correct result is at http://dev.mysql.com/doc/refman/5.0/en/example-maximum-column-group.html and I'm apparently using the correct SQL. The problem is that the columns are not coming out correctly - the rows considered for the max functio

Re: Error with max and group by

2008-06-20 Thread Perrin Harkins
On Fri, Jun 20, 2008 at 10:50 PM, Joe Pearl <[EMAIL PROTECTED]> wrote: > I want to get back only the most recent entry for each person and I don't > care about the order. I want the result to show Jim with the acq_date of > "2008-01-03", Mary and Sally with the location and date for all of them.

Error with max and group by

2008-06-20 Thread Joe Pearl
item_id, location, max(acq_date) from cust_full group by name; +---+-+--+---+ | name | item_id | location | max(acq_date) | +---+-+--+---+ | Jim | 1 | OH | 2008-01-03| | John | 0 | | -00

Re: Do I need to use GROUP BY to do this?

2008-06-18 Thread Ian Simpson
I happen to have worked on a similar query this morning, so it's in my mind :) SELECT SUBSTRING(sales_date,1,10), COUNT(sales_id) FROM sales_activity WHERE sales_type = 1 GROUP BY SUBSTRING(sales_date,1,10); should do the trick. On Tue, 2008-06-17 at 18:21 -0700, Grant Giddens wrote:

Re: Do I need to use GROUP BY to do this?

2008-06-18 Thread Sebastian Mendel
Re: Do I need to use GROUP BY to do this? yes Grant Giddens schrieb: Hi,   I have a table where I keep sales transactions, so I'm trying to do a query that will count the number of transactions per day. My test data looks like: What type of query do I need to get that inform

Do I need to use GROUP BY to do this?

2008-06-18 Thread Grant Giddens
Hi,   I have a table where I keep sales transactions, so I'm trying to do a query that will count the number of transactions per day. My test data looks like: -- -- Table structure for table `sales_activity` -- CREATE TABLE `sales_activity` (   `sales_id` int(11) NOT NULL auto_increment,   `

Re: trouble with group by and similar tables

2008-06-06 Thread Eben
table1.some_field = 'value' AND table2.id1 = table1.id GROUP BY table1.id This works fine and returns each record in table1, grouped by id, with the sum of scores from table2. However, when I do this query: SELECT table1.id,SUM(table2.score) as table2_score, SUM(table3.score) as table3_s

  1   2   3   4   5   6   7   8   9   >