Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Beispiele für Case-Ausdrücke > Selektive Aggregation

Selektive Aggregation

In Kapitel 9 zeigte ich Ihnen bereits eine Teillösung für ein Beispiel, in dem gezeigt wurde, wie man Konten ermittelt, deren Salden nicht mit den Rohdaten in der transaction-Tabelle übereinstimmen. Die Lösung stellte ich nur zum Teil vor, da für eine vollständige Lösung Bedingungslogik erforderlich ist. Da auch dieses Thema nun behandelt wurde, kann ich Ihnen endlich die vollständige Lösung zeigen. Hier sehen Sie das, was in Kapitel 9 weggelassen wurde:

SELECT CONCAT('ALERT! : Account #', a.account_id,
  ' Has Incorrect Balance!')
FROM account a
WHERE (a.avail_balance, a.pending_balance) <>
 (SELECT SUM(<expression to generate available balance>),
    SUM(<expression to generate pending balance>)
  FROM transaction t
  WHERE t.account_id = a.account_id);

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial