English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have 2 tables.
Table 1 has 2 columns: From and to having some interger values
Table 2 has a column having interger values, which may or may not lie between range specified from "To" value to "From" value.

I have to make a query, to count the number of entries in table 2 which lie in the range decided by "To" - "From"

Please help.

2006-08-08 19:46:27 · 5 answers · asked by Sanjeev G 1 in Computers & Internet Programming & Design

What is wrong with this SQL query:
Update table1,table2 set table1.col1 = count(*) where ((table1.col2 > table2.col1) and (table1.col3 < table2. col1))

2006-08-08 19:59:00 · update #1

5 answers

Table 1 (F, T) and Table 2 (V)
F: From, T: To and V: Value

Query:
SELECT table1.F, Table1.T, Count(TABLE2.V) FROM Table1, Table2 where Table2.v >= table1.f and table2.v <= table1.t
group by table1.f, table1.t;

Reg. your additional details query, the normal SQL query would be:
assuming C is the column to store count of values in range
Update Table1 Set C = (Select count(*) from Table2 where v >= table1.f and v <= table1.t)

What you have provided is wrong. You cant update two tables at a time in an Update statement.

2006-08-08 20:16:05 · answer #1 · answered by Indian_Male 4 · 0 0

select count(*) from table1
where table1.column1 in ( select table2.column2 from table1 where table2.column2 between Input lower value and input.upper value.
hope this helps

2006-08-08 20:33:48 · answer #2 · answered by harrypotter 1 · 0 0

let us assume table1 has fields A,B and table2 has field C
try this query

select * from table1, table2 where table2.C between table1.A and table1.B

2006-08-08 19:52:34 · answer #3 · answered by gansatanswers 3 · 0 0

You may use the access query tool "Advanced Access Builder" at http://www.download5000.com/page25449.aspx , it allows you to visually build complete SQL scripts.

2006-08-12 01:31:28 · answer #4 · answered by weida 2 · 0 0

attempt this decide on Admin, SUM(AddType) AS upload, SUM(DeleteType) AS Delete, SUM(ModifyType) AS adjust, count style(*) AS count style FROM (decide on AdminName AS Admin, CASE while RequestType = "upload" THEN one million ELSE 0 end AS AddType, CASE while RequestType = "Delete" THEN one million ELSE 0 end AS DeleteType, CASE while RequestType = "adjust" THEN one million ELSE 0 end AS ModifyType) team by applying Admin

2016-11-04 04:41:27 · answer #5 · answered by Anonymous · 0 0

fedest.com, questions and answers