![]() |
|
#1
|
|||
|
|||
COUNT() from multiple tables with conditionsHello all,
I am semi-new to SQL and am trying to build a query. I have two tables: [Routes] RouteID: int Status: int [Meters] MeterID: int RouteID: int Reading: real I would like to select Routes.Status and a count for the total number of Meters and a count for the unread meters (Reading = NULL) where Meters.RouteID = Routes.RouteID. My Current SELECT statement looks like: Code:
Thanks -fakepoo |
|||
|
#2
|
||||
|
||||
Re: COUNT() from multiple tables with conditionsI suppose you could simply calculate the difference as `TotalUnread`. Maybe something like this:
Code:
Of course I have no way of (really) testing this SQL but it gives you an idea to simply insert a simple subtraction to get the total unread meters. |
|
#3
|
|||
|
|||
Re: COUNT() from multiple tables with conditionsThank you admin. Clearly, I have a long way to go but this helped me over a hump. I'm sure I'll have more questions along the way.
|
|
#4
|
|||
|
|||
Re: COUNT() from multiple tables with conditionsOK. Now I have another problem. I have decided that each Meter now belongs to an Address record instead of a Route record. Routes will now contain Address records.
[Routes] RouteID: int Status: int [Addresses] AddressID: int RouteID: int Address: nvarchar [Meters] MeterID: int AddressID: int Reading: real Now, I would like to get the number of addresses per route, the number of meters per route, and the number of unread meters per route. I am, instead, getting really large numbers like it is counting every meter that is equal to another meter or something. Thanks, ~fakepoo |
|
#5
|
|||
|
|||
Re: COUNT() from multiple tables with conditionsSorry, but there was not a problem with my query. My database had duplicate AddressID values and that was causing weird results.
|
Recent GIDBlog
Configuring iptables for Webmin Servers Index Module by gidnetwork
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to find a mathematical formula for this recursion? | transgalactic | C Programming Language | 8 | 12-Oct-2008 07:43 |
| registering new users, inserting into multiple tables | eb_webdeveloper | MySQL / PHP Forum | 4 | 22-Sep-2006 09:10 |
| HELP!! New to C! | diveboy866 | C Programming Language | 4 | 23-Mar-2006 08:41 |
| Linker errors with multiple file progam | nkhambal | C Programming Language | 2 | 24-Apr-2005 02:37 |
| Count entries from 2 tables | misunderstood | MySQL / PHP Forum | 6 | 31-May-2004 16:45 |
Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The