Hi,
i have a table that has the following fields:
id, name, dept, pay
1, John, Sales, 4000
2, Peter, HR, 5000
etc.
How do i count how many people there are in each dept with an sql query?
I find this surprisingly difficult, given the fact that i can sum the total
pay for each dept by using:
$query="
Select sum(if (dept='HR', pay, 0)) as hrpay, ......
";
TIA 14 6601
"dottty" <do****@noemail pls.met> wrote in message
news:44******** *************** @news.sunsite.d k... Hi, i have a table that has the following fields: id, name, dept, pay 1, John, Sales, 4000 2, Peter, HR, 5000 etc.
How do i count how many people there are in each dept with an sql query?
I find this surprisingly difficult, given the fact that i can sum the
total pay for each dept by using: $query=" Select sum(if (dept='HR', pay, 0)) as hrpay, ...... ";
TIA
SELECT Count(dept) AS deptcount
FROM [table]
GROUP BY id
On Thu, 02 Mar 2006 11:41:12 +0800, dottty wrote: Hi, i have a table that has the following fields: id, name, dept, pay 1, John, Sales, 4000 2, Peter, HR, 5000 etc.
How do i count how many people there are in each dept with an sql query?
I find this surprisingly difficult, given the fact that i can sum the total pay for each dept by using: $query=" Select sum(if (dept='HR', pay, 0)) as hrpay, ...... ";
TIA
Blimey, is that sql? Given the standard rider about this *not* being a
mysql support group, something like the (untested) suggestion below might
help:
select dept, count(*), sum(pay) from ... group by dept, order by dept;
Steve
Hi,
Thanks for the prompt reply. However, i think it should be GROUP BY dept.
cheers
"Bosconian" <bo*******@plan etx.com> wrote in message
news:_p******** *************** *******@comcast .com... "dottty" <do****@noemail pls.met> wrote in message news:44******** *************** @news.sunsite.d k... Hi, i have a table that has the following fields: id, name, dept, pay 1, John, Sales, 4000 2, Peter, HR, 5000 etc.
How do i count how many people there are in each dept with an sql query?
I find this surprisingly difficult, given the fact that i can sum the total pay for each dept by using: $query=" Select sum(if (dept='HR', pay, 0)) as hrpay, ...... ";
TIA
SELECT Count(dept) AS deptcount FROM [table] GROUP BY id
Hi Steve,
Thanks for the reply. It works.
i am aware that this is not a sql group, but i beg your indulgence, as i am
quite sure that you guys will respond,
because i believe that most folks who use PHP
will also be using mysql.
is that correct?
cheers
"Steve" <Th*****@Aint.V alid> wrote in message
news:pa******** *************** *****@Aint.Vali d... On Thu, 02 Mar 2006 11:41:12 +0800, dottty wrote:
Hi, i have a table that has the following fields: id, name, dept, pay 1, John, Sales, 4000 2, Peter, HR, 5000 etc.
How do i count how many people there are in each dept with an sql query?
I find this surprisingly difficult, given the fact that i can sum the total pay for each dept by using: $query=" Select sum(if (dept='HR', pay, 0)) as hrpay, ...... ";
TIA
Blimey, is that sql? Given the standard rider about this *not* being a mysql support group, something like the (untested) suggestion below might help:
select dept, count(*), sum(pay) from ... group by dept, order by dept;
Steve
no.mail.pls wrote: Hi Steve,
Thanks for the reply. It works. i am aware that this is not a sql group, but i beg your indulgence, as i am quite sure that you guys will respond, because i believe that most folks who use PHP will also be using mysql.
is that correct?
cheers "Steve" <Th*****@Aint.V alid> wrote in message news:pa******** *************** *****@Aint.Vali d...
On Thu, 02 Mar 2006 11:41:12 +0800, dottty wrote:
Hi, i have a table that has the following fields: id, name, dept, pay 1, John, Sales, 4000 2, Peter, HR, 5000 etc.
How do i count how many people there are in each dept with an sql query?
I find this surprisingly difficult, given the fact that i can sum the total pay for each dept by using: $query=" Select sum(if (dept='HR', pay, 0)) as hrpay, ...... ";
TIA
Blimey, is that sql? Given the standard rider about this *not* being a mysql support group, something like the (untested) suggestion below might help:
select dept, count(*), sum(pay) from ... group by dept, order by dept;
Steve
No, it is not correct. Many use Postgres SQL, SQL Server, other
databases or no database at all.
You should ask MySQL question in a MySQL newsgroup - such as
comp.databases. mysql. *Everyone* there uses MySQL.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== ===
"no.mail.pl s" <no*****@st.pet ers> wrote in message
news:44******** *************** @news.sunsite.d k... Hi,
Thanks for the prompt reply. However, i think it should be GROUP BY dept.
cheers
"Bosconian" <bo*******@plan etx.com> wrote in message news:_p******** *************** *******@comcast .com... "dottty" <do****@noemail pls.met> wrote in message news:44******** *************** @news.sunsite.d k... Hi, i have a table that has the following fields: id, name, dept, pay 1, John, Sales, 4000 2, Peter, HR, 5000 etc.
How do i count how many people there are in each dept with an sql
query? I find this surprisingly difficult, given the fact that i can sum the total pay for each dept by using: $query=" Select sum(if (dept='HR', pay, 0)) as hrpay, ...... ";
TIA
SELECT Count(dept) AS deptcount FROM [table] GROUP BY id
You're right and I know better. Serves me right for responding hastily just
as the pizza's being delivered. :-]
"no.mail.pl s" <no*****@st.pet ers> wrote in message
news:44******** *************** @news.sunsite.d k... Hi Steve,
Thanks for the reply. It works. i am aware that this is not a sql group, but i beg your indulgence, as i
am quite sure that you guys will respond, because i believe that most folks who use PHP will also be using mysql.
is that correct?
cheers "Steve" <Th*****@Aint.V alid> wrote in message news:pa******** *************** *****@Aint.Vali d... On Thu, 02 Mar 2006 11:41:12 +0800, dottty wrote:
Hi, i have a table that has the following fields: id, name, dept, pay 1, John, Sales, 4000 2, Peter, HR, 5000 etc.
How do i count how many people there are in each dept with an sql
query? I find this surprisingly difficult, given the fact that i can sum the total pay for each dept by using: $query=" Select sum(if (dept='HR', pay, 0)) as hrpay, ...... ";
TIA
Blimey, is that sql? Given the standard rider about this *not* being a mysql support group, something like the (untested) suggestion below
might help:
select dept, count(*), sum(pay) from ... group by dept, order by dept;
Steve
I'm with you. PHP and MySQL are virtually joined at the hip. Look no further
than www.opensourcecms.com for proof. bo*******@plane tx.com says... because i believe that most folks who use PHP will also be using mysql.
I'm with you. PHP and MySQL are virtually joined at the hip. Look no further than www.opensourcecms.com for proof.
And yet here I sit churning away on PHP/AdoDB/Oracle ...
comp.databases. mysql is far better for straight MySQL advice.
Geoff M
Hiya,
Thanks for all the responses. i have never used mysql usenet groups, so i
just popped in to take a look, and found that they are at least an order
less popular than the php groups. On my ISP, i found the following number of
posts for these groups:
comp.lang.php - 22296 posts
comp.databases. mysql - 1067 posts
alt.comp.databa ses.mysql - 128 posts
i know it is a poor excuse for posting here though, but it is kind of you
folks to reply.
The huge difference in the number of posts sets me wondering... is it much
easier to use SQL than PHP, and so there is nothing much to discuss? Or are
there some other reasons?
cheers
"Geoff Muldoon" <ge***********@ trap.gmail.com> wrote in message
news:MP******** *************** *@news.readfree news.net... bo*******@plane tx.com says...
> because i believe that most folks who use PHP > will also be using mysql.
I'm with you. PHP and MySQL are virtually joined at the hip. Look no further than www.opensourcecms.com for proof.
And yet here I sit churning away on PHP/AdoDB/Oracle ...
comp.databases. mysql is far better for straight MySQL advice.
Geoff M This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: 'bonehead |
last post by:
Greetings,
I'd like to figure out some syntax for retrieving the data from a table
when I don't know all the of field names. What I do know are, the name
of the table, the names of the primary key fields, and the names of the
fields I want to use in the "where" clause of the SELECT statement. All
of the examples I've seen in my books only show how to do this by
hard-coding the names of each of the fields, i.e.,
$userid=$query_data;
|
by: Xenophobe |
last post by:
I know this isn't a MySQL forum, but my question is related to a PHP
project.
I have two tables.
table1
table2
"table1" contains 2 columns, ID and FirstName:
|
by: denisb |
last post by:
hello all,
for a search engine, I'm looking for a regexp than can do the job
it is just (!) a 's' problem (frequent in french) :
I have a field 'thesaurus' in a table MySQL (3.23.56) ;
I have a field 'search' in a form where user can input a word ;
what I want is :
|
by: news |
last post by:
I'm trying out the Zend Development Environment 4, and for the most
part I like it, except for two things.
It seems to think certain lines that are perfectly valid are bugs. Like
this:
while ($row_pass = mysql_fetch_array($result_pass)) {
It gives an "Assignment in Condition" error whenever it encounters a
line like that, which is a lot. It gives a little explanation box
|
by: jaysonsch |
last post by:
Hello!
I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the new values are updated
in all corresponding tables (the function of the pages in question).
However, on the page that does the DB update, I also want to do some
checks on the data before performing the update.
Now, the problem that I am...
| |
by: Graham Simms |
last post by:
I have tried to run a query where the reuslts are restricted by a
HAVING clause with 2 conditions, but the second condition seems to be
ignored.
for example
SELECT userid, AVG(position) FROM `table1` WHERE (status='finished')
GROUP BY userid HAVING (COUNT(*) >= 4 AND AVG(position) < 5.5)
returns exactly the same as
|
by: Ljoha |
last post by:
I need to create report where will be shown total quantity of all rows
for every hour in some data range.
I have a table where I have column in DATETIME format. I have problem
to create sql query where I have to get result of the all counts for
every hour of the date range.
Something like that:
from starting hour to final hour = total row count (if there is an
entries),
from 01:00 to 02:00 = 5,
|
by: Zeeshan |
last post by:
Hi everybody,
How can I get rownum using MySQL queries ,
In Oracle one can you in this way SELECT rownum as srno, fname FROM
tablename
suppose If there are 45 records and if i use while for the
srno should display 1, 2, 3, ... 45
query like SELECT rownum as srno, fname FROM tablename
|
by: MP |
last post by:
vb6,ado,mdb,win2k
i pass the sql string to the .Execute method on the open connection to
Table_Name(const) db table
fwiw
(the connection opened via class wrapper:)
msConnString = "Data Source=" & msDbFilename
moConn.Properties("Persist Security Info") = False
moConn.ConnectionString = msConnString
moConn.CursorLocation = adUseClient
moConn.Mode = adModeReadWrite' or using default...same result
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |