473,772 Members | 3,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

count(*) and ORDER by the result of count

bilibytes
128 New Member
Hi everyone,

Ok I want here to make a query which will reuse the result of a count(*) function.


lets say my website does events at different places for the same date, and also at different dates:
this makes a structure like this:
Expand|Select|Wrap|Line Numbers
  1. event_id | attending_id | date 
there may be for the SAME date:
-multiple records with the same event_id and different attending_id
("different attendants to the same event for a specific date")
-multiple records with different event_id and different attending_id
("different attendants are going to different events the same date")

repeat these two possibilities for different dates

i could have:
Expand|Select|Wrap|Line Numbers
  1. date1 - john - best poker
  2. date1 - bob  - best poker
  3. date1 - pip  - best poker
  4. date1 - ron   - poker unite
  5. date1 - clo   - poker unite
  6. date1 - foo   - poker unite
  7. date1 - fos   - poker unite
  8. date1 - koh   - gold poker
  9. date2 - ron   - poker unite
  10. date2 - bob  - poker unite
  11. date3 - bob  - poker unite
  12. data3 - mar  - poker hacks
i would like to count the number o attendants for each event at a specific date.

Expand|Select|Wrap|Line Numbers
  1. SELECT count(*)
  2.         FROM attending 
  3.         WHERE attending.date = '$date'
  4.         ORDER by the most populated events 
i would like to get:
(for date1)
Expand|Select|Wrap|Line Numbers
  1. poker unite 4
  2. best poker 3
  3. gold poker 1
is there a way to perform this?


PD: in my real table the events are stored under id (numbers), so i should then get the names for each event from another table would that be possible in the same query?

thankyou

bilibytes
Nov 10 '08 #1
1 3223
bilibytes
128 New Member
Got the answer,

when you try to ORDER by count(*), you should use AS like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT count(*) AS what_you_count ORDER by 'what_you_count'
AS creates like an alias to the result array
Nov 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2742
by: JaNE | last post by:
Maybe this isn't the most apropriate place to ask mysql related question, but I think it is close enought to most php users and I always got find answers on this group. well, I need to count how meny rows have some maximum number. here is exact situation (striped down table) (pictID, jpeg name, #of votes) pict1, name1.jpg, 4 pict2, name2.jpg, 22 pict3, name3.jpg, 5
6
1816
by: Good Man | last post by:
Hi all Well, I didn't want to have to bring this question to someone else to answer, but I am truly flummoxed and could use some help. It all boils down to trying to find the number of jobs available in a particular state. I have two tables, one called STATES and one called WORK. Here are excerpts from both: STATES table: StateID | StateName | StateAbbr
2
1626
by: bsder | last post by:
Hi, If I want to select a result that based on the value of count (eg. count(*) > 5), how can I write a sql to do that? eg. select count(*)>5 from Flight where OperationType = "Departure" group by Airline, Runway
18
9766
by: war_wheelan | last post by:
I am very new to Transact-SQL programming and don't have a programming background and was hoping that someone could point me in the right direction. I have a SELECT statement SELECT FIXID, COUNT(*) AS IOIs and want to ORDER BY 'IOI's'. I have been combing through the BOL, but I don't even know what topic/heading this would fall under. USE INDII SELECT FIXID, COUNT(*) AS IOIs FROM . GROUP BY FIXID
2
2992
by: pierrelap | last post by:
Hello, I need to code a query that: 1-counts the number of time two companies have been in a deal together 2-in the five years that preceded the deal Lead Participant DealDate AAA BBB 01/01/1990 BBB AAA 01/01/1991 AAA BBB 01/01/1992 AAA BBB 01/01/1993 AAA BBB 01/01/1994
2
2054
by: bhu | last post by:
How to get a unique count from a xml <Orders> <Order ID="1111" Amount="200"></Order> <Order ID= "2222" Amount="10"></Order> <Order ID="3333" Amount="5"></Order> <Order ID="1111" Amount="20"></Order> </Orders> The result should be 3 unique count and the 4 Order Id counts. How can i get using XPathNodeIterator using Compile,Execute with a XPathNavigator
12
4930
by: petter | last post by:
Hi! I have two questions: one question that regards the COUNT-function, and one about how to display a month even if I don’t have any data for that month. I have an Access database where I want to create a query to count all the internal units in my list (the “input”-table), between two dates. I want my list to be grouped by year and month. Here is the SQL-code, as called from VBA: strSQL_INTU1 = "PARAMETERS DateTime, DateTime;" _ ...
3
2512
by: Hasse1982 | last post by:
Hi I have a table KDOCUMENT with the columns , , , , , ,
1
3203
by: claudfs | last post by:
Hey Guys, Ok here is my problem: There is around 350 rows in the db. All the variables $actor_id, $comment_id and $likes_id are all uid's for facebook users Now i want to group and sum how many entries there are of each unique uid
0
9620
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9912
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.