I know this has been asked but I don't have access to JOIN or pretty much anything with the Teredata SQL assistant and I want to know why this doesn't work. I have a subquery that displays the name of an agent and counts their transactions for destinations to France. If they have over 10 transactions to France the number of transactions and names are displayed.
I want to take this working SELECT statement and put it as a sub query. Then I want to only take the agent_name from this sub query.
Why won't it let me do this?
I tried:
DATABASE database;
SELECT agent_name FROM
(SELECT COUNT (*) number, agent_name
FROM TRANSAC
WHERE TRANSAC.cust_name = CUSTOMER.cname
AND CUSTOMER.destination = 'France'
GROUP BY agent_name
HAVING COUNT(*) > 9;)
and I tried
DATABASE database;
SELECT agent_name FROM TRANSAC WHERE agent_name IN
(SELECT COUNT (*) number, agent_name
FROM TRANSAC
WHERE TRANSAC.cust_name = CUSTOMER.cname
AND CUSTOMER.destination = 'France'
GROUP BY agent_name
HAVING COUNT(*) > 9;)
Update you can select from a subquery by using an alias
DATABASE redeclectus;
SELECT t.agent_name
FROM
(SELECT COUNT (*) number, agent_name FROM TRANSAC
WHERE TRANSAC.cust_name = CUSTOMER.cname AND
CUSTOMER.destination = 'Ottawa'
GROUP BY agent_name
HAVING COUNT(*) > 9) t;
Aucun commentaire:
Enregistrer un commentaire