Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MYSQL


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Invalid Use Of Group Function - Max(`mainid`)+1


I am trying to insert a incremented number into the menu table. I will have an autoincremented number as well as the mainid number. When I tested the code that is below, the above error happened. Can someone please tell me the correct way of doing this? I am getting really frustrated with this. Nothing wants to work for me.

require "config.php";
$insert06 = "INSERT INTO `menu` (`mainid`)
                VALUES (max(`mainid`)+1)"; // error line
if (mysql_query ($insert06)) {
    print "Mainid added.";
    $query2 = mysql_query("SELECT mainid FROM menu") or die ("Could not query because: ".mysql_error());
    while($row2 = mysql_fetch_array($query2)) {
        echo $row2['mainid']." = Mainid";
    }
} else {
    print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $insert06.</p>";
}
mysql_close();




View Complete Forum Thread with Replies

Related Forum Messages:
Invalid Use Of Group Function & SUM() And MAX()
I have the following Sql Statement... I'd like to find the sum of hrs worked by an employee in the month, the required number of hrs, and the sum of the difference between the two, the worked hrs are calculated by subtracting the max vtranstime - min vtranstime and the required hrs are calculated by subtracting max to1 - max from1....

View Replies !
Error:invalid Use Of Group Function
version:mysql 4.0.18 for win

hi,all dear:)

when execute sql-statement,
error raise:

update customer,cu_order set customer_point=0
where customer_keyid=order_customerid and
DATE_SUB(now(),INTERVAL 1 YEAR)=DATE_FORMAT(max(order_time),"%Y-%m-%d 23:59:59")

error:invalid use of group function

i beg someone tells me why?how resolve?

thx

View Replies !
Invalid Use Of Group Function (was "Baffled By Query Error")
trying to figure out why I keep getting this error with the following query:

SELECT c.account_id,a.name,a.company,SUM(c.agent_product_time) AS mins
FROM account a LEFT JOIN calls c ON c.account_id = a.id
WHERE c.calldate >= DATE_SUB(NOW(),INTERVAL 14 DAY) AND c.agent_id = 2
AND SUM(c.agent_product_time) >= '500' GROUP BY c.account_id ORDER BY mins

ERROR: #1111 - Invalid use of group function

View Replies !
Invalid Use Of Group By
I have the following query:

SELECT CLAIMPOLICYNUMBER AS Plan, PROVIDERSPECIALTY AS Specialty, TINNUM AS Tin, SUBTINSEQNUM AS SibTin, CHARGETYPECATEGORY AS ChargeCategory, SUM(BILLEDCHARGE) AS Billed, SUM(PAID) AS Paid, " + _
COUNT(DOCUMENTNUM) AS ChgCount
FROM BAT
WHERE CASENUM='0000911'
AND CHARGETYPE <> 'DENTAL' AND CHARGETYPE <> 'VISION' AND CHARGETYPE <> 'ADMIN'
AND PMTDATE >= '2005-06-01' AND PMTDATE <= '2005-06-30'
GROUP BY CLAIMPOLICYNUMBER, PROVIDERSPECIALTY, TINNUM, SUBTINSEQNUM, CHARGETYPECATEGORY
ORDER BY SUM(BILLEDCHARGE)

It works great without the ORDER BY clause, but with it, I get the aforementioned error.

View Replies !
Group By Returns Invalid Dates
Hi i have one table:

ID, User, Score, Date
1, mac, 1234, 2007-12-09 09:01:07
2,kurca, 3232, 2007-12-05 09:43:57
3, mac, 999999, 2007-11-07 09:44:14

I wan to create a high score list which will represent the best scores but not repeating anyone for example:
1, mac, 999999, 2007-11-07 09:44:14
2,kurca, 3232, 2007-12-05 09:43:57


Now i use:
SELECT ID, User,MAX(Score) as maxScore,Date
FROM `table`
GROUP BY User
ORDER BY maxScore DESC

with this query the score is right but the date is invalid example:
1, mac, 999999,2007-12-09 09:01:07
2,kurca, 3232, 2007-12-05 09:43:57

View Replies !
IF Function,GROUP BY,aggregate Function Problems
Yep, I have all those problems in the title. So I'll explain each one at a time - I did have another thread relating to this very same query but I thought it was time to update where I am with the query because at the moment I feel like I am getting nowhere!

The query I have basically searches through an items_ordered table through each product and checks to see whether the item is VATable or not. This is not where I have the problem though. Where I am really having the first problem is when I am trying to use the IF function to check if the TOTAL of an order is over £300. IF it is then I multiply it my 0.95 (i.e. 5% off). With the query below I get no errors but neither do I get the desired result. It's as though it couldn't even see it. =....

View Replies !
MAX(mainid) Isn't Working For Me???
I am wanting to get the last inserted mainid number then insert back into a different row at a higher number. For example if the inserted mainid was 1 the next number should be 2. The code below isn't working for me. It just adds 0 to the mainid column. Can someone please tell me if there is a better way of doing this? Thanks in advance.

Here is my

PHP
require "config.php";
// more code here
$insert1 = "INSERT INTO `menu` (`mainid`)
                            SELECT max(mainid) + 1
                           FROM menu";
                if (mysql_query ($insert1)) {
                    $query1 = mysql_query("SELECT LAST_INSERT_ID() as id FROM menu") or die ("Could not query because: ".mysql_error());
                    $row1 = mysql_fetch_assoc($query1);
                    $id1 = $row1['id'];
                    $update1 = "UPDATE menu SET menu = '$menu', pagetitleMenu = 'Menu', pagetitle2 = '$pagetitle', pagetitleSub = 'none', subid = &#390;', submenu = '$submenuyesno' WHERE mainid = '$id1'";
// more code here
mysql_close();

View Replies !
Group Function
I have a table salary, and when I select it, it looks like this ....

View Replies !
Count Function & Group By
Getting an error saying I cannot Group on JState2

Is this a version issue? What is an alternate?
(want to show only results having greater than 2 of the same JState 's)

SELECT COUNT(JState) as JState2, JID, StateTerm
FROM JPosts2, State
WHERE State.StateAbbr=JPosts2.JState AND (`JClass` = 'Mechanics')
GROUP BY JState2 HAVING JState2 >4
ORDER BY JState

View Replies !
GROUP BY Function And Getting Rid Of NULL Results
Ok, here is a query I'm doing:

SELECT site , sum(uniques ), sum(trials +full_price ), round(sum(uniques)/sum(trials +full_price )) as ratio FROM mpa3_all_stats WHERE date BETWEEN '2005-12-01' AND '2005-12-15' GROUP BY site

What I want to do is get rid of the null results that I'm getting from this return. As if I order by the last field, the nulls will go to the top if it's ASC. Which I need to do a ASC order on the last column. But I can't figure out a while to get rid of the null results. I've searched everything I could think it would be under.

Here is partial data I'm getting:

Code:


+------+----------------+----------------------------+------------------------------------------------------+
| site | sum( uniques ) | sum( trials + full_price ) | round( sum( uniques ) / sum( trials + full_price ) ) |
+------+----------------+----------------------------+------------------------------------------------------+
| 18 | 99865 | 119 | 839 |
| 19 | 121386 | 188 | 646 |
| 20 | 479 | 0 | NULL |
| 21 | 1314 | 0 | NULL |
| 22 | 100541 | 226 | 445 |
| 33 | 21457 | 169 | 127 |
+------+----------------+----------------------------+------------------------------------------------------+

View Replies !
Invalid Use
I am having a problem with group. Following is my query but it gives an error of "Invalid use of group".

SELECT refMember.MemberAcroName, refMember.MemberName, Count(DistrictLevelInformation.FormID) AS Spread
FROM (refMember LEFT JOIN MainInformation ON refMember.MemberID = MainInformation.MemberID) LEFT JOIN DistrictLevelInformation ON MainInformation.ID = DistrictLevelInformation.FormID
GROUP BY refMember.MemberAcroName, refMember.MemberName, MainInformation.qYear, MainInformation.Quarter
ORDER BY MainInformation.qYear DESC , MainInformation.Quarter DESC , Count(DistrictLevelInformation.FormID) DESC

View Replies !
Invalid Database Name
"show databases"
Code:

Databases
usernames.May2007
usernames.June2007
usernames

When I execute "use usernames.May2007" I get error:
Code:

Error 1102 (42000) : Invalid database name 'usernames.May2007'

I don't now need to keep the '..2007' databases but how do I delete them?
I get a similar error when I use drop usernames.May2007

View Replies !
Invalid Index
I try to used the MyPhpAdmin 2.8.2.4 with PHP 4.4.4, MySQL5.0.2.4 and Apcache2 and I got this error, 'invalid Index'

View Replies !
Directory Name Invalid
For testing purposes I have PHP installed and I have MySQL installed on my local laptop. Windows XP Pro

I am just learning both of them. I have read quite a few chapters in the MySQL Manual. Enough to allow me to get around in MySQL and directly create tables an view information in them, upload .txt files into the tables, etc etc.

I am receiving an error when I try to connect to MySQL via a PHP script.
I have no problem connecting to MySQL via Command Line.

The error I receive is "The directory name is invalid."

Here is my code... I am not sure where to put the directory name or where to put the directory path in order to make it valid. I am not sure what directory it is talking about.

<html>
<head><title>Connect to MySQL</title></head>
<body>
<?php
//connecting to the mysql server uses a mysql_connect command.
$link = mysql_connect("locoalhost",$_POST['username'],$_POST['password']) or die("Connect Error: ", . mysql_error());
echo 'Successfully Connected.
';
mysql_close($link);
?>
</body>
</html>

Where exactly would I put the path to the directory or where would I name the directory?

View Replies !
Invalid Syntax
I am having trouble changing my password back to OLD_PASSWORD by the following :

mysql> SET PASSWORD FOR
-> 'some_user'@'some_host' = OLD_PASSWORD('newpwd');

When I do it, it says
ERROR 1064: 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 'OLD_PASSWORD ('newpwd')' at line 2

View Replies !
#1067 - Invalid Default Value For 'id'
SQL query:

CREATE TABLE users(
id int( 10 ) DEFAULT '0' NOT NULL AUTO_INCREMENT ,
username varchar( 40 ) ,
PASSWORD varchar( 50 ) ,
regdate varchar( 20 ) ,
email varchar( 100 ) ,
website varchar( 150 ) ,
location varchar( 150 ) ,
show_email int( 2 ) DEFAULT '0',
last_login varchar( 20 ) ,
PRIMARY KEY ( id )
)

MySQL said: Documentation
#1067 - Invalid default value for 'id'
please help? What do i need to change. Using 5.0.51-community

View Replies !
Mysql 4: Invalid Database Name
"show databases"

Databases
usernames.May2007
usernames.June2007
usernames

When I execute "use usernames.May2007" I get error:Error 1102 (42000) : Invalid database name 'usernames.May2007'I don't now need to keep the '..2007' databases but how do I delete them?
I get a similar error when I use drop usernames.May2007

View Replies !
Invalid Argument While Using BCP (Script)
This will be a 50/50 question. It's either something that the SQL experts can answer or a scripting forum. I'm new to SQL and just coming to grips with getting familiar with scripts. I've developed a small script for my workplace that will connect to a remote server and extract the specified table that I want, zip it up and then copy it back to my local machine. This works fine until it tries to run the bcp command.
If I tivoli to the remote machine and type the bcp command in command prompt it works fine. However when executed from the script it throws an invalid argument and seems to refer to the "-" minus I place in front of the U (user) or P(pwd). The script echos the users table request to a file which is then copied to the remote server (SQLtable.cmd) and then PSEXEC is called to connect to the server and run the script. e.g. psexec \%Server% -u %user% -p %password% "C: empSQLtable.cmd"
PSEXEC then returns the following error.

C:WINNTSYSTEM32>Bcp FrontOff..SHIFT_TER_DATA out C: empdmpnlSHIFT_TER_DATA.dat ûUsa ûPpwd (chopped off the -n)
Unknown argument '¹Usa' on command line.

Sorry about all the data, just hope someone can help. Must be an easy way. The small script which psexec is executing contains two simple lines. Bcp FrontOff..SHIFT_TER_DATA out C: empdmpnlSHIFT_TER_DATA.dat -Usa -Ppwd -n
wwzip -9 C: emp\%username%SQLtables.zip C: emp\%username%*.*

View Replies !
Dropping Database With Invalid Name
I'm using MySQL 4.1.20, and I was somehow able to create a dabatase with a period in it, which I later found out is an invalid character. Well, now it won't let me drop the database or even view its contents. When I try to do anything involving it, I get the following message:

#1102 - Incorrect database name 'xxxxxxx.xxx'

View Replies !
Invalid Access To Memory Location.
I have a hosted account - I'm getting this error now..... Any reason that I can hunt down to figure out why I should be getting it?

View Replies !
Valid/Invalid Column Names
I'd like to present tabular data in HTML with the first row being the names of the columns in my database. However, I'd like them to be more presentable; for example 'I.P. Address' instead of 'ip_address'. I was wondering if a name like 'I.P. Address' could ever somehow be a valid column name or not.

View Replies !
Strip Invalid Char From Tables
Just wondering if anyone knows a way I can run a query to strip out commas from a table?

View Replies !
Table Join Invalid Query
I have this table join below and I am getting an invalid query. How can I put the 15th line ($sql .= " group.id = master.id
"; and the 17th line ($sql .= " where ".$currentrow_sql ; together. Is it even possible to do that?

View Replies !
Invalid MySQL-Link Resource
I'm getting the error message 'Supplied argument is not a valid MySQL-Link resource' (applies to the 3rd line of code) when the code below executes:

$delete_part_no_query = "DELETE FROM prices WHERE part_no == '$part_no_to_delete'";

$delete_part_no_result = mysql_query($delete_part_no_query);

$num_delete_part_no_result = mysql_affected_rows($delete_part_no_result);

The query works fine and I'm under the impression that 'mysql_affected_rows' should be used to return the number of rows affected by DELETE. However, I keep getting the above error message.

View Replies !
Mysqlhotcopy Error :: Invalid Db.table Name
I have a large database that I'm unable to backup with mysqldump.

So I tried mysqlhotcopy , testing it on a smaller wordpress installation as:

mysqlhotcopy bestfood_word /path/to/new_directory

But it gave me this error:

Invalid db.table name 'bestfood_word.bestfood_word`.`wp_categories' at /usr/bin/mysqlhotcopy line 854.

Could anyone tell me what would cause this and if I should use a different command?

View Replies !
Is There Any MySql Function Which Is Equalent To Oracle Last_Value Function
I am converting Oracle view to MySql where I am having the follwoing syntax in Oracle
last_value(col1 ignore nulls) over (partition by col2 order by col2, col3 rows between unbounded preceding and 1 preceding)

which I need to convert to MySql.

View Replies !
Illegal Mix Of Collations :: Invalid Characters Are Coming
i have php and MySQL 4.1.11 installed on my linux box,i am getting error for mix of collation when i use find_in_set php function also some invalid characters are coming on site from db.

error is

#1267 - Illegal mix of collations (utf8_general_ci,COERCIBLE) and (latin1_swedish_ci,IMPLICIT) for operation 'find_in_set'

View Replies !
Invalid Distinct Recordset Returned On An Indexed Column
I have a table with about 1.2 million records. I have an index set on a column.

For close to two years, this query has worked perfectly fine:

SELECT DISTINCT `Mgmt_Area` as thevalue, `Mgmt_Area` as valueid from qcdata ORDER BY thevalue

Note, this is a programmatically generated query based on some user selections. This query actually is used to create a listbox. The index has 62 separate values.

This query would usually return: Code:

View Replies !
Importing CSV :: Invalid Field Count In CSV Input On Line 1
I was able to import a csv file without any problems, until my server updated phpmyadmin from 2.6.4 pl2 to 2.8.02. now when I try to import the same file I get the following error.

Error:
Invalid field count in CSV input on line 1.

View Replies !
Full Yearly Weekly Group By Group Report
I have table called tblTransactions:

TblTransactions
Group | Months | Year | Transaction
A | 3 | 2007 | 45
B | 2 | 2007 | 89
A | 7 | 2007 | 50
A | 8 | 2007 | 34
B | 4 | 2007 | 55
A |12 | 2007 | 10
A | 1 | 2008 | 88
B | 3 | 2008 | 34
B | 5 | 2008 | 70
A | 5 | 2008 | 45
A | 9 | 2008 | 88
B | 7 | 2008 | 99
A |10 | 2008 | 77
A |11 | 2008 | 99

How is the T-SQL to make the result like this (the result will display all of the week (FULL), the target is I can compare week by week between years and group.

A | 1 | 2007 | 0
B | 1 | 2007 | 0
A | 2 | 2007 | 0
B | 2 | 2007 | 89
A | 3 | 2007 | 45
B | 3 | 2007 | 0
A | 4 | 2007 | 0
B | 4 | 2007 | 55
A | 5 | 2007 | 0
B | 5 | 2007 | 0
A | 6 | 2007 | 0
B | 6 | 2007 | 0
A | 7 | 2007 | 50
B | 7 | 2007 | 0
A | 8 | 2007 | 34
B | 8 | 2007 | 0
A | 9 | 2007 | 0
B | 9 | 2007 | 0
A | 10| 2007 | 0
B | 10| 2007 | 0
A | 11| 2007 | 0
B | 11| 2007 | 0
A | 12| 2007 | 10
B | 12| 2007 | 0
A | 1 | 2008 | 88
B | 1 | 2008 | 0
A | 2 | 2008 | 0
B | 2 | 2008 | 0
A | 3 | 2008 | 0
B | 3 | 2008 | 34
A | 4 | 2008 | 0
B | 4 | 2008 | 0
A | 5 | 2008 | 45
B | 5 | 2008 | 70
A | 6 | 2008 | 0
B | 6 | 2008 | 0
A | 7 | 2008 | 0
B | 7 | 2008 | 99
A | 8 | 2008 | 0
B | 8 | 2008 | 0
A | 9 | 2008 | 88
B | 9 | 2008 | 0
A |10 | 2008 | 77
B |10 | 2008 | 0
A |11 | 2008 | 99
B |11 | 2008 | 0
A |12 | 2008 | 0
B |12 | 2008 | 0

View Replies !
Warning: Mysql_data_seek(): Offset 0 Is Invalid For MySQL Result Index 2
I only posted this on the MySQL forums becouse i believed it had to do with the query.

I get the following error:

Warning: mysql_data_seek(): Offset 0 is invalid for MySQL result index 2 (or the query data is unbuffered)

mysql_data_seek is used in a function (made not by me) which i know 500% that it works for other queries.

The query in PHP is this:

View Replies !
Group By With Order BY, Or INSERT INTO (SELECT * GROUP BY)?
I seem to have a few duplicates entries in a very large database.

My database has two identical tables. One is written to on a regular basis (every few seconds) and the other is used for queries, and updated from the write table on a daily basis.

I'm trying to get rid of duplicate entries for the queries, and I thought the most effective way to do this would be to run the query as
Expand|Select|Wrap|Line Numbers

View Replies !
GROUP BY With Order Inside Group
I have a problem when grouping records - I can't manipulate data inside group. For example,

I have table `images` with fields `name` (name of image, not unique) and `dtadded` (date of image adding). Then, I need to get all images names with distinct names where each name must be latest added name.
Sample:
------------------------------
id, name, dtadded
------------------------------
1 name1 2007-10-15 00:00:00
2 name2 2007-10-15 00:00:00
3 name1 2007-10-16 00:00:00
------------------------------

I need to receive 2 results (for each name)
3 - name1 - 2007-10-16 00:00:00
2 - name2 - 2007-10-15 00:00:00

If I use SQL code:

SELECT images.id, images.dtadded, images.name, count(name)
FROM images
GROUP BY `name`
ORDER BY dtadded DESC

I get results
1 - name1 - 2007-10-15 00:00:00
2 - name2 - 2007-10-15 00:00:00

It groups records with first row in database, but I need last row in table for each name.

Question: How can I order results in side group to get needed results as described above?

View Replies !
Top Record From Each Group In GROUP BY
I never could figure out a good way to do this.
I am doing a group by statement, and want the top record from each group to be returned only. My query is to find the current win/loss streak for each team.
Here is the sql:
SELECT
id,
team_name,
result,
MIN(date) AS startdate,
MAX(date) AS enddate,
COUNT(*) AS games
FROM (
SELECT
t.id,
t.team_name,
sched.date,
CASE sched.draw
WHEN 1 THEN 'draw'
ELSE CASE sched.winner_id
WHEN t.id THEN 'win'
ELSE 'loss'
END
END AS result,
(
SELECT COUNT(*)
FROM fantasy_schedule sched2
WHERE ( CASE sched2.draw
WHEN 1 THEN 'draw'
ELSE CASE sched2.winner_id
WHEN t.id THEN 'win'
ELSE 'loss'
END
END ) <> result
AND sched2.date >= &#55614;&#57157;-01-01' AND sched2.date < &#55614;&#57158;-01-01'
AND sched2.date < sched.date
AND sched2.fantasy_league_id = 6
AND (sched2.fantasy_team1_id = t.id OR sched2.fantasy_team2_id = t.id)
) AS rungroup
FROM fantasy_schedule sched
JOIN fantasy_team t ON t.id = sched.fantasy_team1_id OR t.id = sched.fantasy_team2_id
WHERE sched.last_update < NOW()
AND sched.date >= &#55614;&#57157;-01-01' AND sched.date < &#55614;&#57158;-01-01'
AND sched.fantasy_league_id = 6
) bighonker
GROUP BY id, team_name, result, rungroup
ORDER BY enddate DESC
And a subset of what is returned:


+----+----------------------------+--------+------------+------------+-------+
| id | team_name | result | startdate | enddate | games |
+----+----------------------------+--------+------------+------------+-------+
| 1 | The Macho King | loss | 2005-12-17 | 2005-12-17 | 1 |
| 1 | The Macho King | win | 2005-12-11 | 2005-12-11 | 1 |
| 1 | The Macho King | loss | 2005-11-24 | 2005-12-04 | 2 |
| 1 | The Macho King | win | 2005-11-20 | 2005-11-20 | 1 |
| 1 | The Macho King | loss | 2005-11-13 | 2005-11-13 | 1 |
| 1 | The Macho King | win | 2005-10-30 | 2005-11-06 | 2 |
| 1 | The Macho King | loss | 2005-10-16 | 2005-10-23 | 2 |
| 1 | The Macho King | win | 2005-10-09 | 2005-10-09 | 1 |
| 1 | The Macho King | loss | 2005-10-02 | 2005-10-02 | 1 |
| 1 | The Macho King | win | 2005-09-08 | 2005-09-25 | 3 |
| 2 | General Grievous | loss | 2005-12-17 | 2005-12-17 | 1 |
| 2 | General Grievous | win | 2005-12-11 | 2005-12-11 | 1 |
| 2 | General Grievous | loss | 2005-11-24 | 2005-12-04 | 2 |
| 2 | General Grievous | win | 2005-11-13 | 2005-11-20 | 2 |
| 2 | General Grievous | loss | 2005-11-06 | 2005-11-06 | 1 |
| 2 | General Grievous | win | 2005-10-23 | 2005-10-30 | 2 |
| 2 | General Grievous | loss | 2005-10-16 | 2005-10-16 | 1 |
| 2 | General Grievous | win | 2005-10-02 | 2005-10-09 | 2 |
| 2 | General Grievous | loss | 2005-09-08 | 2005-09-25 | 3 |
| 3 | Ultimate Jarin | win | 2005-11-06 | 2005-12-24 | 8 |
| 3 | Ultimate Jarin | loss | 2005-10-23 | 2005-10-30 | 2 |
| 3 | Ultimate Jarin | win | 2005-10-09 | 2005-10-16 | 2 |
| 3 | Ultimate Jarin | loss | 2005-09-25 | 2005-10-02 | 2 |
| 3 | Ultimate Jarin | win | 2005-09-08 | 2005-09-18 | 2 |
| 4 | The Hulkamaniacs | loss | 2005-12-11 | 2005-12-11 | 1 |
| 4 | The Hulkamaniacs | win | 2005-12-04 | 2005-12-04 | 1 |
| 4 | The Hulkamaniacs | loss | 2005-11-24 | 2005-11-24 | 1 |
| 4 | The Hulkamaniacs | win | 2005-11-06 | 2005-11-20 | 3 |
| 4 | The Hulkamaniacs | loss | 2005-10-30 | 2005-10-30 | 1 |
| 4 | The Hulkamaniacs | win | 2005-10-09 | 2005-10-23 | 3 |
| 4 | The Hulkamaniacs | loss | 2005-09-18 | 2005-10-02 | 3 |
| 4 | The Hulkamaniacs | win | 2005-09-08 | 2005-09-08 | 1 |
| 5 | WHO WANTS TO KISS HOMER? | win | 2005-12-04 | 2005-12-04 | 1 |
| 5 | WHO WANTS TO KISS HOMER? | loss | 2005-11-20 | 2005-11-24 | 2 |
| 5 | WHO WANTS TO KISS HOMER? | win | 2005-11-13 | 2005-11-13 | 1 |
The top record in each group is the current streak. I want only that top record for each teamr returned. I could simply 'order by enddate DESC' and in my php script loop until I have one record per team, but is there any way I can only return the top result for each team in the query itself?

Here is the corresponding table schema:



+-------------------+---------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+---------------------+------+-----+---------------------+----------------+
| id | int(10) unsigned | | PRI | NULL | auto_increment |
| fantasy_league_id | int(10) unsigned | | MUL | 0 | |
| week_num | tinyint(3) unsigned | | MUL | 0 | |
| fantasy_team1_id | int(10) unsigned | | MUL | 0 | |
| fantasy_team2_id | int(10) unsigned | | MUL | 0 | |
| winner_id | int(10) unsigned | YES | | 0 | |
| date | date | | | 0000-00-00 | |
| last_update | datetime | | | 0000-00-00 00:00:00 | |
| draw | tinyint(3) unsigned | | | 0 | |
+-------------------+---------------------+------+-----+---------------------+----------------+

fantasy_team
+---------------------+-----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+-----------------------+------+-----+---------+----------------+
| id | int(10) unsigned | | PRI | NULL | auto_increment |
| fantasy_league_id | int(10) unsigned | | MUL | 0 | |
| user_id | mediumint(8) unsigned | | MUL | 0 | |
| team_name | char(40) | | | | |
| fantasy_division_id | int(10) unsigned | YES | MUL | NULL |
+---------------------+-----------------------+------+-----+---------+----------------+


View Replies !
Max Function
I have a table with name, priority and parent as three columns...I want to get the max(priority) grouped by the parent... I am trying to get name, priority, parent, max(parent) as the four columns in the result...Could some one help me with this

select name, priority, parent from table1
select max(priority) from table1 group by parent

are the two select statements that I wish to combine...is it possible..?

View Replies !
SQL IN() Function
so i have a query such as
SELECT first_name FROM users WHERE user_ID IN (5,4,8,19,8,4) and i want the first_name to be retrieved for EACH of the cases (eg. name is repeated twice for 4 and 8)

View Replies !
Last Function
How do you get the last row in a grouped query. I have a table with running balances. At the end of the day, I want to find out the last balance.

select *
from accounts
group by date(dateCol)

This always gives me the first row of the grouped column dateCol.

View Replies !
Avg Function
Why doesn't this work:

SELECT avg(value) as avg_value from playerstats where avg_value = '100' and stattype = 'r' group by avg_value

I'm trying to select the avg_value of 'r' where the avg_value = '100'.

View Replies !
Looking For A Particular Function
I have a Column which consists of only DATE's and an ID code. I want to enumerate all the DATE's of a certain ID to get a grand total of a ID. Does such a function exist?

View Replies !
Using The AVG Function
I am trying to use this query:

SELECT average(price) FROM `data` WHERE id IN ( '3', '3', '6' )

to average the price of items users select. The problem is that when a user selects a value more than once it only includes it in the average once. How can I make it average all the values?

View Replies !
Now() Function
I am using now function to get current date when info is added to my table. I am using a hosting provider that is 6 hrs ahead in time zone so i always have to subtract 6hrs to get the correct time. Is there anyway I can format the time to be inserted to my time zone?

View Replies !
SOUNDEX Function
I'm using SOUNDEX mysql function to find similar sounding names from
a table with 2 million distinct names.

Unfortunately there is a single soundex code for every 200,000 names!
Meaning there are only 200,000 distinct codes for 2 million entries.

Is there any other function / library / technique to work around this
immense 1:10 redundancy ?

for example, soundex for 'avis', 'apex' and 'apps' is A120, but I'd
like to differentiate between them in my search - meaning implement a
"stricter" sound comparison than the soundex function offers.

View Replies !
Group_concat Function
I am attempting to pull data from multiple tables into a resultset that
I can use as an Excel spreadsheet for reporting. Code:

View Replies !
MBREquals Function
Has the MBREquals function been implemented in the latest 4.1.1-alpha
build. I am finding problems with that command. It says that problem is
there in sql syntax. If it has been implemented. Can you please help me
in the syntax of the command.I am finding the same problems with the
Intersection,Union,difference,symdifferenc commands But manual says that
they are not yet implemented. So I guess they are not yet implemented.

View Replies !
Equivalent Function
I use the following function in Oracle
SELEC T decode(status,'A','Active','L','Active','Former') FROM Table

What it means is: if status = A, return "Active", if status=L, return
"Active", else return "Former" in the select statement.

Decode in mysql has nothing to do with this functionality and I didnt see a
function while browsing the docs online that did this. Is there an
equivalent function in mySQL?

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved