You are here: Re: SQL help, please « MsSQL Server « IT news, forums, messages
Re: SQL help, please

Posted by Hugo Kornelis on 11/02/05 00:20

On 1 Nov 2005 13:38:22 -0500, triciam wrote:

>I am using this query but it’s not working, please help
>
>select customers.customerid, customers.country,
>orders.orderid, orders.orderdate, orderdetails. sum(unitprice) as
>TotalSales
>from customers, orders, orderdetails
>left join orders on customers.customerid = orders.customerid
>where orderdate > ’11/1/4’
>and country <> ’USA’
>and unitprice > 0
>and orderid > 346544
>group by orderid
>order by orderid
>
>This is the error message that I’m getting:
>ables or functions ’orders’ and ’orders’ have the same exposed names.
>Use correlation names to distinguish them.
> I’m not sure how to make this work......... Thank You Tricia :)

Hi Tricia,

I'll have to make some pretty big assumptions in my answer. Next time
you post, you might want to include CREATE TABLE statements to show us
how the tables look, INSERT statements with sample data and the expected
results. See www.aspfaq.com/5006 for more details.

For your query, you might try the following:

SELECT c.customerid, c.country, o.orderid, o.orderdate,
SUM(od.unitprice) AS TotalSales
FROM customers AS c
INNER JOIN orders AS o
ON o.customerid = c.customerid
INNER JOIN orderdetails AS od
ON od.orderid - o.orderid
WHERE o.orderdate > '11/1/4' -- but see below
AND c.country <> 'USA'
AND od.unitproce > 0
AND o.orderid > 346544
GROUP BY o.orderid, o.orderdate, c.customerid, c.country
ORDER BY o.orderid

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация