[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] [SQL] group by hjælp



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kristian Nørgaard wrote:
> Min SQL syntax er lidt rusten...
> - hvordan får jeg en liste med alle bøgers billigste pris og salgsted?
> 
> Tabel:
> 
> --id-----bogtitel ------  salgsted ------ pris
> 
> 1    'Linux A-Z'            'Amazon'    '200'
> 2    'Linux A-Z'            'Metro'        '180'
> 3    'Mit liv som tux'    'Bogladen'    '99'
> 4    'Mit liv som tux'     'Amazon'    '199'
> 5    'Nørder'                 'Metro'          '50'
> 
> 
> svaret må gerne være MYSQL kompatibelt
> / Kristian
> 

Følgende eksperiment er lavet i MySQL

mysql> select * from t2;
+----+-----------------+-----------+------+
| id | bogtitel        | salgssted | pris |
+----+-----------------+-----------+------+
|  1 | Linux A-Z       | Amazon    |  200 |
|  2 | Linux A-Z       | Metro     |  180 |
|  3 | Mit liv som Tux | Bogladen  |   99 |
|  4 | Mit liv som Tux | Amazon    |  199 |
|  5 | N               | Metro     |   50 |
+----+-----------------+-----------+------+
5 rows in set (0.00 sec)

Dette passer til dit oplæg.

Prøv nu:
mysql> select id,bogtitel,salgssted,min(pris) from t2 group by bogtitel;
+----+-----------------+-----------+-----------+
| id | bogtitel        | salgssted | min(pris) |
+----+-----------------+-----------+-----------+
|  1 | Linux A-Z       | Amazon    |       180 |
|  3 | Mit liv som Tux | Bogladen  |        99 |
|  5 | N               | Metro     |        50 |
+----+-----------------+-----------+-----------+
3 rows in set (0.00 sec)

Sådan læste jeg dit spørgsmål.


- --
Niels Müller Larsen
Programmør, MSc

Mob: +45 2040 5740
Web: http://deformation.org
Public key: 0xD4DB4A5E
(http://keyserver.veridis.com:11371/search?q=0xD4DB4A5E)


This fortune was brought to you by the people at Hewlett-Packard.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGYVmCbiU629TbSl4RAvG/AJ0Q5AiasycSG0Ylo7WqDMTfpnTuxwCffztH
0LDdYOOWOcK3AAf72l//WYc=
=H9nT
-----END PGP SIGNATURE-----


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2007-07-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *