Click here to Skip to main content
16,008,299 members
Home / Discussions / Database
   

Database

 
QuestionHow to run the Job Pin
Atul Kharecha25-Sep-06 23:50
Atul Kharecha25-Sep-06 23:50 
AnswerRe: How to run the Job Pin
Dave Kreskowiak27-Sep-06 13:48
mveDave Kreskowiak27-Sep-06 13:48 
QuestionHow ca i remove spaces in my database ? Pin
Bravoone_200625-Sep-06 21:09
Bravoone_200625-Sep-06 21:09 
QuestionIdentity reset Pin
FireOnMoon25-Sep-06 18:35
FireOnMoon25-Sep-06 18:35 
AnswerRe: Identity reset Pin
_AK_25-Sep-06 22:37
_AK_25-Sep-06 22:37 
AnswerRe: Identity reset Pin
Colin Angus Mackay26-Sep-06 0:57
Colin Angus Mackay26-Sep-06 0:57 
QuestionComplicate SQL question...?? anyone know? urgent~~ Pin
campbells25-Sep-06 17:33
campbells25-Sep-06 17:33 
AnswerRe: Complicate SQL question...?? anyone know? urgent~~ Pin
Michael Potter26-Sep-06 5:24
Michael Potter26-Sep-06 5:24 
The sample query you list has both Department and Vendor in it (you could get departments listed more than once if they use different vendors). You are trying to get a percentage of total for each department but your sample result set lists no percentages and values are listed by vendor. Are you sure you know what you really need?

Given your 2nd line and assuming you are using SQL Server, first calculate a good total sales per department.
SELECT 
    d.deptdesc,
    SUM(ti.totalsales) AS DeptTotal 
FROM 
    tot_item ti 
INNER JOIN 
    dept d
    ON (ti.deptcode=d.deptcode)

Now write a query that calculates total sales.
SELECT
    SUM(ti.totalsales) AS FullTotal
FROM 
    tot_item ti 

Now put them together
SELECT
    dep.deptdesc,
    (dep.DeptTotal /
     (SELECT
         SUM(ti.totalsales)
      FROM 
         tot_item ti)) * 100 AS PercentOfSales
FROM
    (SELECT 
         d.deptdesc,
         SUM(ti.totalsales) AS DeptTotal 
     FROM 
         tot_item ti 
     INNER JOIN 
         dept d
         ON (ti.deptcode=d.deptcode)) AS dep
ORDER BY
    deptdesc

Note: I am using a more modern form of the JOIN syntax. There are issues with expressing the JOIN in the WHERE clause. You can make this a lot cleaner using variables in a stored proc.
GeneralRe: Complicate SQL question...?? anyone know? urgent~~ Pin
Michael Potter27-Sep-06 3:14
Michael Potter27-Sep-06 3:14 
AnswerRe: Complicate SQL question...?? anyone know? urgent~~ Pin
ednrgc19-Oct-06 6:29
ednrgc19-Oct-06 6:29 
QuestionOOD and Databases... Pin
Shy Agam25-Sep-06 3:39
Shy Agam25-Sep-06 3:39 
AnswerRe: OOD and Databases... Pin
Paddy Boyd25-Sep-06 4:10
Paddy Boyd25-Sep-06 4:10 
QuestionCheck referential integrity in SQL 2005 Pin
Vipul Mehta25-Sep-06 1:20
Vipul Mehta25-Sep-06 1:20 
AnswerRe: Check referential integrity in SQL 2005 Pin
M LN Rao25-Sep-06 2:35
M LN Rao25-Sep-06 2:35 
QuestionDatabase question. very urgent [modified] Pin
riyasath24-Sep-06 16:12
riyasath24-Sep-06 16:12 
AnswerWord of advice... Pin
leckey24-Sep-06 18:37
leckey24-Sep-06 18:37 
AnswerRe: Database question. very urgent Pin
alexisxavior24-Sep-06 19:36
alexisxavior24-Sep-06 19:36 
GeneralRe: Database question. very urgent Pin
riyasath24-Sep-06 20:39
riyasath24-Sep-06 20:39 
AnswerRe: Database question. very urgent Pin
Mike Dimmick25-Sep-06 0:19
Mike Dimmick25-Sep-06 0:19 
GeneralRe: Database question. very urgent Pin
riyasath25-Sep-06 16:41
riyasath25-Sep-06 16:41 
QuestionAutomating cross-table record(s) transferring Pin
iskaza24-Sep-06 10:18
iskaza24-Sep-06 10:18 
AnswerRe: Automating cross-table record(s) transferring Pin
Rob Graham24-Sep-06 11:15
Rob Graham24-Sep-06 11:15 
GeneralRe: Automating cross-table record(s) transferring Pin
iskaza24-Sep-06 11:47
iskaza24-Sep-06 11:47 
QuestionAutomating cross-table record(s) transferring(FollowUp) [modified] Pin
iskaza24-Sep-06 13:19
iskaza24-Sep-06 13:19 
QuestionADO Recordsets in VC++ Pin
eusto24-Sep-06 5:09
eusto24-Sep-06 5:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.