Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested query

Status
Not open for further replies.

JasonXie

Programmer
Feb 4, 2001
20
0
0
NZ
Hello,All:

As we all know, a simple query S_q is of a standard form, i.e. select ... from ... where... group by ... having ... sorted by ...
Actually, a nested query N_q may contain other simple queries with standard form (or even other nested queries) in the where clause/from clause/having clause of N_q.

My questions are:

Whether there exists a software or a method which can convert a nested query into a simple query ?

Whether there exists a software or a method which can convert a simple query with having clause to one without having clause ?

Many thanks in advance.
 
Hi,

There are some software oackages that try and optimize queries and whilst doing this will re-create the statement for you - sometimes the better query isn't necessarily the simplest looking one.

Lecco Soft - SQL Expert Pro
Quest Software - SQL Lab Xpert

These are two I've seen, I know there are many more.

 
i want to form a query that will have output the total amount from a sales table in a quarterly period. the output should have 5 clouns year, qtr1, qtr2, qtr3, qtr4. though the table has only 2 comuns, date (dd/mm/yyyy) and the amount.
i did manage to get the total for the forst qtr jan-feb-march, but i need to get the second and third column now... any help available?
 
Hummmmmm, moonhearts, hummmmm, OOOOOOOdd,

Anyway, try to use a nested query.

For example,
If you have got these:
Q1 :
select sum(amount) as qtr1
from sales
where date in (Jan, Feb, Mar) ( or something like this )

Q2:
select sum(amount) as qtr2
from sales
where date in (Apr, May, Jun)

...


You might be able to use the follows:

select sum(amount) as year, qtr1,qtr2,qtr3,qtr4
from sales, (body of Q1),(body of Q2),...

I have not tested it. Becuase MySQL doesn't support the nested query.

Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top