Most data sort

Most data sort

am 21.12.2009 08:31:36 von HaidarPesebe

------=_NextPart_000_0BDB_01CA824A.4D4552A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Dear All,

I need your help to how to call the database.

I've got a mysql database as follows:
------------------
Name | qty
-----------------
A 1
B 2
A 4
A 1
B 1
A 2
C 2
D 1
C 4

How calling if I want to sort the data according to the most, or the =
result will look like this

A =3D 7
C =3D 6
B =3D 3
D =3D 1

Thanks a lot
Haidarpesebe
------=_NextPart_000_0BDB_01CA824A.4D4552A0--

Re: Most data sort

am 21.12.2009 11:22:57 von Yang Wang

c2FtcGxlIGFzIGJlbG93IHdpdGggZ3JvdXAgYnkgYW5kIG9yZGVyIGJ5IHN0 YXRtZW50DQoNCg0K
bXlzcWw+IGNyZWF0ZSB0YWJsZSB0MihuYW1lIGNoYXIoMSkscXR5IHNtYWxs aW50KTsNClF1ZXJ5
IE9LLCAwIHJvd3MgYWZmZWN0ZWQgKDAuMDEgc2VjKQ0KDQpteXNxbD4gaW5z ZXJ0IGludG8gdDIg
dmFsdWVzKCdBJywxKSwoJ0InLDIpLCgnQScsNCksKCdBJywxKSwoJ0EnLDEp LCgnQicsMSksKCdB
JywyKSwoJ0MnLDIpLCgnRCcsMSksKCdDJyw0KTsNClF1ZXJ5IE9LLCAxMCBy b3dzIGFmZmVjdGVk
ICgwLjAwIHNlYykNClJlY29yZHM6IDEwICBEdXBsaWNhdGVzOiAwICBXYXJu aW5nczogMA0KDQpt
eXNxbD4gc2VsZWN0ICogZnJvbSB0MjsNCistLS0tLS0rLS0tLS0tKw0KfCBu YW1lIHwgcXR5ICB8
DQorLS0tLS0tKy0tLS0tLSsNCnwgQSAgICB8ICAgIDEgfA0KfCBCICAgIHwg ICAgMiB8DQp8IEEg
ICAgfCAgICA0IHwNCnwgQSAgICB8ICAgIDEgfA0KfCBBICAgIHwgICAgMSB8 DQp8IEIgICAgfCAg
ICAxIHwNCnwgQSAgICB8ICAgIDIgfA0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QogRCAgICAgMQ0KIEMgICAgIDQNCg0KSG93IGNhbGxp bmcgaWYgSSB3YW50
IHRvIHNvcnQgdGhlIGRhdGEgYWNjb3JkaW5nIHRvIHRoZSBtb3N0LCBvciB0 aGUgcmVzdWx0IHdp
bGwgbG9vayBsaWtlIHRoaXMNCg0KQSA9IDcNCkMgPSA2DQpCID0gMw0KRCA9 IDENCg0KVGhhbmtz
IGEgbG90DQpIYWlkYXJwZXNlYmU=

Re: Most data sort

am 21.12.2009 11:29:15 von HaidarPesebe

Thanks Mr. Wang,
I will try and inform you again if have a problem.

Best regard,
Haidar Pesebe


----- Original Message -----
From: "Yang Wang"
To: "HaidarPesebe" ; "MySQL Lists"

Sent: Monday, December 21, 2009 5:22 PM
Subject: Re: Most data sort


> sample as below with group by and order by statment
>
>
> mysql> create table t2(name char(1),qty smallint);
> Query OK, 0 rows affected (0.01 sec)
>
> mysql> insert into t2
> values('A',1),('B',2),('A',4),('A',1),('A',1),('B',1),('A',2 ),('C',2),('D',1),('C',4);
> Query OK, 10 rows affected (0.00 sec)
> Records: 10 Duplicates: 0 Warnings: 0
>
> mysql> select * from t2;
> +------+------+
> | name | qty |
> +------+------+
> | A | 1 |
> | B | 2 |
> | A | 4 |
> | A | 1 |
> | A | 1 |
> | B | 1 |
> | A | 2 |
> | C | 2 |
> | D | 1 |
> | C | 4 |
> +------+------+
> 10 rows in set (0.00 sec)
>
> mysql> select name,sum(qty) as qty from t2 group by name order by qty
> desc;
> +------+------+
> | name | qty |
> +------+------+
> | A | 9 |
> | C | 6 |
> | B | 3 |
> | D | 1 |
> +------+------+
> 4 rows in set (0.01 sec)
>
>
>
>
> Best Regards!
> Yang Wang
>
>
> ----- Original Message -----
> From: "HaidarPesebe"
> To: "MySQL Lists"
> Sent: Monday, December 21, 2009 3:31 PM
> Subject: Most data sort
>
>
> Dear All,
>
> I need your help to how to call the database.
>
> I've got a mysql database as follows:
> ------------------
> Name | qty
> -----------------
> A 1
> B 2
> A 4
> A 1
> B 1
> A 2
> C 2
> D 1
> C 4
>
> How calling if I want to sort the data according to the most, or the
> result will look like this
>
> A = 7
> C = 6
> B = 3
> D = 1
>
> Thanks a lot
> Haidarpesebe


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: Most data sort

am 21.12.2009 11:46:47 von HaidarPesebe

Dear Mr. Wang,

I've tried and the results are in accordance with the intended.
Your description is very brief and precise

Thank you Mr. Wang.

With best regard,
Haidar Pesebe


----- Original Message -----
From: "HaidarPesebe"
To: "Yang Wang" ; "MySQL Lists"

Sent: Monday, December 21, 2009 5:29 PM
Subject: Re: Most data sort


> Thanks Mr. Wang,
> I will try and inform you again if have a problem.
>
> Best regard,
> Haidar Pesebe
>
>
> ----- Original Message -----
> From: "Yang Wang"
> To: "HaidarPesebe" ; "MySQL Lists"
>
> Sent: Monday, December 21, 2009 5:22 PM
> Subject: Re: Most data sort
>
>
>> sample as below with group by and order by statment
>>
>>
>> mysql> create table t2(name char(1),qty smallint);
>> Query OK, 0 rows affected (0.01 sec)
>>
>> mysql> insert into t2
>> values('A',1),('B',2),('A',4),('A',1),('A',1),('B',1),('A',2 ),('C',2),('D',1),('C',4);
>> Query OK, 10 rows affected (0.00 sec)
>> Records: 10 Duplicates: 0 Warnings: 0
>>
>> mysql> select * from t2;
>> +------+------+
>> | name | qty |
>> +------+------+
>> | A | 1 |
>> | B | 2 |
>> | A | 4 |
>> | A | 1 |
>> | A | 1 |
>> | B | 1 |
>> | A | 2 |
>> | C | 2 |
>> | D | 1 |
>> | C | 4 |
>> +------+------+
>> 10 rows in set (0.00 sec)
>>
>> mysql> select name,sum(qty) as qty from t2 group by name order by qty
>> desc;
>> +------+------+
>> | name | qty |
>> +------+------+
>> | A | 9 |
>> | C | 6 |
>> | B | 3 |
>> | D | 1 |
>> +------+------+
>> 4 rows in set (0.01 sec)
>>
>>
>>
>>
>> Best Regards!
>> Yang Wang
>>
>>
>> ----- Original Message -----
>> From: "HaidarPesebe"
>> To: "MySQL Lists"
>> Sent: Monday, December 21, 2009 3:31 PM
>> Subject: Most data sort
>>
>>
>> Dear All,
>>
>> I need your help to how to call the database.
>>
>> I've got a mysql database as follows:
>> ------------------
>> Name | qty
>> -----------------
>> A 1
>> B 2
>> A 4
>> A 1
>> B 1
>> A 2
>> C 2
>> D 1
>> C 4
>>
>> How calling if I want to sort the data according to the most, or the
>> result will look like this
>>
>> A = 7
>> C = 6
>> B = 3
>> D = 1
>>
>> Thanks a lot
>> Haidarpesebe
>
>
> __________ Information from ESET Smart Security, version of virus
> signature database 4704 (20091220) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org