|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to count the rows of a query result ?
Maybe I worked to long but I have no clue how to solve this !
How can I count the number of rows returned by this query ? (I need to use this value in a stored procedure) SELECT AUTO_ID_CUSTOMER , SUM(UNIT_QTY*UNIT_PRICE) FROM V_TRANSACTIONS WHERE INV_DATE > '01/01/2006' GROUP BY AUTO_ID_CUSTOMER HAVING SUM(UNIT_QTY*UNIT_PRICE) < 100000 I also tried something like select count(distinct v1.auto_id_customer) FROM V_TRANSACTIONS v1 WHERE v1.INV_DATE > '01/01/2006' and (select sum(v2.UNIT_QTY*v2.UNIT_PRICE) FROM V_TRANSACTIONS v2 where v2.auto_id_customer = v1.auto_id_customer and v2.INV_DATE > '01/01/2006') < 100000 which works, but unfortunately the execution time on even a small table is not acceptable (> 1 min.) |
|
#2
|
|||
|
|||
|
Quote:
Does this run any faster? Code:
SELECT COUNT(*) FROM ( SELECT AUTO_ID_CUSTOMER , SUM(UNIT_QTY*UNIT_PRICE) FROM V_TRANSACTIONS WHERE INV_DATE > '01/01/2006' GROUP BY AUTO_ID_CUSTOMER HAVING SUM(UNIT_QTY*UNIT_PRICE) < 100000 ) Clive |
|
#3
|
||||
|
||||
|
On Firebird 2.0
Quote:
__________________
My blog about OpenSource Databases PDF tutorials about OSS databases, DBMonster ... Please contribute to Open Source Development, fill bug reports!!! Developer Shed eSupport Commented my.ini/my.cnf (PLEASE ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins |
![]() |
| Viewing: Dev Shed Forums > Databases > Firebird SQL Development > How to count the rows of a query result ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|