473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

[MySQL] group and max problem...

Witam,
szukając w dokumentacji mysqla odpowiedzi na moje pytanie
trafiłem na taki przykład:

SELECT user, MAX(salary) as max_sel
FROM tmp
GROUP BY user HAVING max_sel = MAX(salary);

I faktycznie w tabeli, która na 2 kolumny wszystko działa dobrze
ale ja potrzebuję czegoś więcej :-)

CREATE TABLE `tmp` (
`id` int(11) NOT NULL auto_increment,
`user` char(50) default NULL,
`salary` int(10) default NULL,
`data` date default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM

wprowadziłem do niej takie dane:
INSERT INTO `tmp` VALUES
(1,'mikolaj',50,'2006-01-01'),
(2,'mikolaj',15,'2004-02-02'),
(3,'mikolaj',20,'2004-03-03'),
(4,'mikolaj3',11,'2004-04-04'),
(5,'mikolaj3',40,'2005-05-05'),
(6,'mikolaj3',25,'2005-05-05');
Po dodaniu do selecta pola `data`

SELECT user, MAX(salary) as max_sel, `data`
FROM tmp
GROUP BY user HAVING max_sel = MAX(salary);

Otrzymuję taki wynik:
user salary data
mikolaj 50 2006-01-01
mikolaj3 40 2004-04-04

1 rekord jest ok (przez przypadek)
a drugi !!! pokazuje pierwszą datę z pogrupowanej grupy,
zamiast wartość `data` z rekordu gdzie jest MAX(salary).
Czy ktoś mógłby mnie oświecić dlaczego tak
się dzieje?
Niestaty nie można dodać po prostu
order by `data`, bo order jest wykonany po group :(

Jak wybrać dobre rekordy bez użycia tabel tymczasowych?
Czy kroś może mi pomóc?

Mysql 4.costam (bez podzapytan).

Mikolajj
Jul 20 '05 #1
0 3297

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: renster | last post by:
Hi, I was wondering if anyone here had a decent solution to this mysql/php problem. I have a mysql database with a list of groups (group_id, group_name, group_location, group_time,...
7
by: atlasyeo | last post by:
Hi, my first time posting on a newsgroup. anyway, let's cut to the chase. I'm trying to migrate mysql database form one server to another server. So I copied the data from /var/lib/mysql to the...
8
by: William Drew | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.databases.mysql This is an invitation to discuss the following proposal to create newsgroup comp.databases.mysql. Please note that YOU...
2
by: Prabu Subroto | last post by:
Dear my friends... I am trying to develop a database application with PHP Version 4.3.2, MS Window 2000, MySQL 4.0.13-nt and Apache 2. I tried to insert a record onto my MySQL but I got this...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
6
by: jacob nikom | last post by:
I would like to create data model for a group of stores. All stores in this group are very similar to each other, so it is natural to allocate one MySQL database per store. Each database is going...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
8
by: sundeep.kumara | last post by:
hi all, I am a newbie .....I have compiled the source code of mysql-4.1.9 on PPC-Linux Its not giving any errors during configure,make or make install. But,when i try to start the server...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
27
by: gerrymcc | last post by:
Hello, I'm a php/mysql beginner... Is there any way of making the mysql command line client full-screen? Sometimes it's easier to use the client than go thru php, but since it's only about 80...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.