Jump to content

please need help with this query!!


KaKoRoT

Recommended Posts

Hi guys, bare with me I have not done any sql coding since when i was at uni,

 

now i can only remember the basics, and all the neat tricks i taught my self are forgotten!!

 

could you help me clean this up as well as get it work properly.

 

//Code Start

 

SELECT sum( swtickettimetrack.timespent ) AS timespent, swtickettimetrack.ticketid, swtickets.ticketid, swtickets.userid, swusers.usergroupid, swusergroups.title, swusergroups.usergroupid

 

FROM swtickets, swusers, swusergroups, swtickettimetrack

 

WHERE swtickettimetrack.ticketid = swtickets.ticketid

 

AND swtickets.userid = swusers.userid

AND swusers.usergroupid = swusergroups.usergroupid

AND swusergroups.title = 'PHASCA'

 

GROUP BY swtickettimetrack.timespent

 

//Code End

 

cant remember how to get it to only display the sum value, I am sure it was something like this (oh yeah and something about alias')

 

SELECT sum( swtickettimetrack.timespent ) AS timespent

FROM swtickettimetrack

 

WHERE (SELECT swtickettimetrack.ticketid, swtickets.ticketid, swtickets.userid, swusers.usergroupid, swusergroups.title, swusergroups.usergroupid

 

FROM swtickets, swusers, swusergroups, swtickettimetrack

 

AND swtickettimetrack.ticketid = swtickets.ticketid

AND swtickets.userid = swusers.userid

AND swusers.usergroupid = swusergroups.usergroupid

AND swusergroups.title = 'PHASCA')

 

GROUP BY swtickettimetrack.timespent;

 

Some hints or tips to help me remember would be nice thanks!!!

Link to comment
Share on other sites

Hi

 

Think you need to do it this way:-

 

SELECT timespent
FROM (
SELECT sum( swtickettimetrack.timespent ) AS timespent, swtickettimetrack.ticketid, swtickets.ticketid, swtickets.userid, swusers.usergroupid, swusergroups.title, swusergroups.usergroupid

FROM swtickets
JOIN swtickettimetrack ON swtickettimetrack.ticketid = swtickets.ticketid
JOIN swusers ON swtickets.userid = swusers.userid
JOIN swusergroups ON swusers.usergroupid = swusergroups.usergroupid

WHERE  swusergroups.title = 'PHASCA'

GROUP BY swtickettimetrack.ticketid, swtickets.ticketid, swtickets.userid, swusers.usergroupid, swusergroups.title, swusergroups.usergroupid)
[code]

All the best

Keith

Link to comment
Share on other sites

Hi Keith, thanks for replying ... unfortunately it doesnt work, I understand why though, but its the reason for it dont work is what i cant remember to do.. "aliases"

 

here is the error..

 

Error

 

SQL query: Documentation

 

SELECT timespent

FROM (

 

SELECT sum( swtickettimetrack.timespent ) AS timespent, swtickettimetrack.ticketid, swtickets.ticketid, swtickets.userid, swusers.usergroupid, swusergroups.title, swusergroups.usergroupid

FROM swtickets

JOIN swtickettimetrack ON swtickettimetrack.ticketid = swtickets.ticketid

JOIN swusers ON swtickets.userid = swusers.userid

JOIN swusergroups ON swusers.usergroupid = swusergroups.usergroupid

WHERE swusergroups.title = 'PHASCA'

GROUP BY swtickettimetrack.ticketid, swtickets.ticketid, swtickets.userid, swusers.usergroupid, swusergroups.title, swusergroups.usergroupid

)

 

MySQL said: Documentation

#1248 - Every derived table must have its own alias

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.