PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > ORDER BY calculated field
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
ORDER BY calculated field

Réponse
 
LinkBack Outils de la discussion
Vieux 20/03/2008, 11h08   #1
Neil Tompkins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut ORDER BY calculated field

Hi,

How do I achieve a SQL statement to order my results based on two calculated fields for example :

SELECT COUNT(ProductsPurchases.ProductID) as varProductCount, Products.Name, Products.ProductReview
FROM ProductsPurchasesINNER JOIN Products ON Products.ProductID = ProductsPurchases.ProductIDGROUP BY Products.ProductID ORDER BY varProductCount+Products.ProductReviewDESC

Thanks
Neil
__________________________________________________ _______________
Telly addicts unite!
http://www.searchgamesbox.com/tvtown.shtml
  Réponse avec citation
Vieux 20/03/2008, 11h36   #2
Sebastian Mendel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: ORDER BY calculated field

Neil Tompkins schrieb:
> Hi,
>
> How do I achieve a SQL statement to order my results based on two calculated fields for example :


what two calculated fields?


> SELECT COUNT(ProductsPurchases.ProductID) as varProductCount, Products.Name, Products.ProductReview
> FROM ProductsPurchasesINNER JOIN Products ON Products.ProductID = ProductsPurchases.ProductIDGROUP BY Products.ProductID ORDER BY varProductCount+Products.ProductReviewDESC


ORDER BY COUNT(ProductsPurchases.ProductID)

--
Sebastian Mendel
  Réponse avec citation
Vieux 20/03/2008, 11h37   #3
Neil Tompkins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: ORDER BY calculated field

Hi

I want to order by the totalled fields varProductCount and Products.ProductReviewDESC

Neil



> Date: Thu, 20 Mar 2008 11:36:30 +0100> From: lists@sebastianmendel.de> To: mysql@lists.mysql.com> Subject: Re: ORDER BY calculated field> > Neil Tompkins schrieb:> > Hi,> > > > How do I achieve a SQL statement to order my results based on two calculated fields for example :> > what two calculated fields?> > > > SELECT COUNT(ProductsPurchases.ProductID) as varProductCount, Products.Name, Products.ProductReview> > FROM ProductsPurchasesINNER JOINProducts ON Products.ProductID = ProductsPurchases.ProductIDGROUP BY Products.ProductID ORDER BY varProductCount+Products.ProductReviewDESC> > ORDER BY COUNT(ProductsPurchases.ProductID)> > -- > Sebastian Mendel> > -- > MySQL General Mailing List> For list archives: http://lists.mysql.com/mysql> To unsubscribe: http://lists.mysql.com/mysql?unsub=neildtompkins@hotmail.com>

__________________________________________________ _______________
Telly addicts unite!
http://www.searchgamesbox.com/tvtown.shtml
  Réponse avec citation
Vieux 20/03/2008, 11h44   #4
Sebastian Mendel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: ORDER BY calculated field

Neil Tompkins schrieb:
> Hi
>
> I want to order by the totalled fields varProductCount and Products.ProductReviewDESC


just put them together, separated with comma, like it is written in the manual

ORDER BY varProductCount + Products.ProductReviewDESC,
COUNT(ProductsPurchases.ProductID)

  Réponse avec citation
Vieux 20/03/2008, 12h59   #5
Sebastian Mendel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: ORDER BY calculated field

Sebastian Mendel schrieb:
> Neil Tompkins schrieb:
>> Hi
>>
>> I want to order by the totalled fields varProductCount and
>> Products.ProductReviewDESC

>
> just put them together, separated with comma, like it is written in the
> manual
>
> ORDER BY varProductCount + Products.ProductReviewDESC,
> COUNT(ProductsPurchases.ProductID)
>


sorry:

ORDER BY COUNT(ProductsPurchases.ProductID) + Products.ProductReviewDESC

--
Sebastian
  Réponse avec citation
Vieux 20/03/2008, 13h03   #6
Neil Tompkins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: ORDER BY calculated field

Thanks Sebastian, but I now get the error message

[MySQL][ODBC 3.51 Driver][mysqld-3.23.58]Invalid use of group function



> Date: Thu, 20 Mar 2008 12:59:22 +0100> From: lists@sebastianmendel.de> To: mysql@lists.mysql.com> Subject: Re: ORDER BY calculated field> > Sebastian Mendel schrieb:> > Neil Tompkins schrieb:> >> Hi> >> > >> I want to orderby the totalled fields varProductCount and > >> Products.ProductReviewDESC> > > > just put them together, separated with comma, like it is written inthe > > manual> > > > ORDER BY varProductCount + Products.ProductReviewDESC,> > COUNT(ProductsPurchases.ProductID)> > > > sorry:> > ORDER BY COUNT(ProductsPurchases.ProductID) + Products.ProductReviewDESC> > -- > Sebastian> > -- > MySQL General Mailing List> For list archives: http://lists.mysql.com/mysql> To unsubscribe: http://lists.mysql.com/mysql?unsub=neildtompkins@hotmail.com>

__________________________________________________ _______________
Share what Santa brought you
https://www.mycooluncool.com
  Réponse avec citation
Vieux 20/03/2008, 13h08   #7
Sebastian Mendel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: ORDER BY calculated field

Neil Tompkins schrieb:
> Thanks Sebastian, but I now get the error message
>
> [MySQL][ODBC 3.51 Driver][mysqld-3.23.58]Invalid use of group function


i am not familiar with ODBC or MySQL 3.x

but possible just GROUP BY is missing
check the manual for your mysql version for the exact syntax

if this is not working at all you have to use HAVING

--
Sebastian
  Réponse avec citation
Vieux 20/03/2008, 13h17   #8
Neil Tompkins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: ORDER BY calculated field

Thanks for the . However I found another solution which is to use the following SELECT COUNT(ProductsPurchases.ProductID)+Products.Produc tReview as varProductCount, Products.Name, Products.ProductReviewFROM ProductsPurchasesINNER JOIN Products ON Products.ProductID = ProductsPurchases.ProductIDGROUP BY Products.ProductID ORDER BY varProductCount DESC

> Date: Thu, 20 Mar 2008 13:08:51 +0100> From: lists@sebastianmendel.de> CC: mysql@lists.mysql.com> Subject: Re: ORDER BY calculated field> > Neil Tompkins schrieb:> > Thanks Sebastian, but I now get the error message> > > > [MySQL][ODBC 3.51 Driver][mysqld-3.23.58]Invalid use of group function> > iam not familiar with ODBC or MySQL 3.x> > but possible just GROUP BY is missing> check the manual for your mysql version for the exact syntax> > if this is not working at all you have to use HAVING> > -- > Sebastian> > -- > MySQL General Mailing List> For list archives: http://lists.mysql.com/mysql> To unsubscribe: http://lists.mysql.com/mysql?unsub=neildtompkins@hotmail.com>

__________________________________________________ _______________
Share what Santa brought you
https://www.mycooluncool.com
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h04.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13859 seconds with 16 queries