If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Null Subquery problem

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-01-10, 04:11
taylankoca taylankoca is offline
Registered User
 
Join Date: Sep 2010
Posts: 1
Null Subquery problem

Hello,

This is my first message in the forum.

Code:
SELECT a.saat, b.saat, MAX( Tgiren + Tcikan ) AS Total
FROM (

SELECT saat, SUM( giren ) AS Tgiren
FROM magaza_sayma
WHERE (
kamera_id
IN (

SELECT cam_id AS cami
FROM katgirencikan
WHERE kat_id =  '2'
AND gc =  'g'
AND gc2 =  'g'
)
)
AND hangi_yil =  '2010'
AND hangi_ay =  '8'
AND ayin_kaci =  '17'
GROUP BY saat
)a, (

SELECT saat, SUM( cikan ) AS Tcikan
FROM magaza_sayma
WHERE (
kamera_id
IN (

SELECT cam_id AS cami
FROM katgirencikan
WHERE kat_id =  '2'
AND gc =  'g'
AND gc2 =  'c'
)
)
AND hangi_yil =  '2010'
AND hangi_ay =  '8'
AND ayin_kaci =  '17'
GROUP BY saat
)b
WHERE a.saat = b.saat
GROUP BY a.saat
ORDER BY Total DESC 
LIMIT 0 , 1
The problem is sometimes the second degree inside query does not return anything, and the whole query returns nothing. I want to change it if the subquery returns nothing, Tgiren or Tcikan equals to 0 so Total can be calculated by only one.

It is very urgent.
Thank you.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On