Hia all
I am having a bit of a Friday moment with some SQL and am hoping someone can show me the light…??
I am sure its very basic – but the finer details are some what eluding me today…
I have this script equivalent…
Select
B.Description
Count(B.Description)
Sum(A.Amount)
From
Table1 A
Join Table2 B on (A.id = B.id)
Where table A has one to many records of table B.
This runs fine, but what I am seeing is an incorrect Sum amount due to this one to many association between the two tables.
i.e. if an ID from Table A has £5 in the Amount column, and the same ID exists on 4 records on Table B – my sum result is coming back at £20, I only want a distinct £5.
My initial thought was to do something like putting Distinct in front of the A.Amount (Sum(Distinct A.Amount)) within the aggregate, but this groups by the money values, and not the ID…
I hope that makes sense to someone out there?!
Many thanks in advance!!
Christopher Hill
Swyddog Dadansoddi a Chymorth SQL
SQL Support Analyst
Canolfan Mileniwm Cymru
Wales Millennium Centre
Ebost\Email Christopher.Hill@wmc.org.uk
Ffon\Tel 029 2063 6372
www.wmc.org.uk
Dy Le Di
Make it Yours this year
Cysylltwch yn Gymraeg neu'n Saesneg fel dymunwch
Contact us in English or Welsh as you prefer
Plas Bute\Bute Place
Bae Caerdydd\Cardiff Bay
CF10 5AL
P Meddyliwch am yr amgylchedd cyn printio / Please consider the environment before printing this email
Does anyone know what table contains the “Inactive” field that displays on the Constituencies screen? It is not located in the tx_const_cust table as I expected. We have constituencies for our staff levels, and when staff changes from one level to another, they end up with multiple constituency entries, so I need to be able to report on the constituencies that are not inactive.
Penny Tabor
IT Manager
Midland Center for the Arts
Midland, MI 48640
Penny,
I don't think this is kept in a table, It is calculated based on the end_dt which is stored in tx_const_cust. For easier use you can also see only active constituencies in the view vxs_const_cust.Dale
I don't think it is stored any where - I think its one of those that is set depending on the end date for the Constituency.
Caryl