title: Summing a field while excluding certain fields in SQL
body: <p>I am trying to suma column in a table, while excluding certain records that have the paid field set to true.</p>
  
  <p>I am doing so like this:</p>
  
  <pre><code>SELECT SUM( cost ) AS total
  FROM sales
  WHERE passport = 'xxxxx'
  AND paid &lt;&gt;1
  </code></pre>
  
  <p>The table is full of data, and I can display costs by themselves, or the entire total. Just adding on 
      AND paid &lt;>1
  Is what causes it to fail. The query does not fail as such, but NULL is returned which is quite useless.</p>
  
  <p>This is the SQL for my table</p>
  
  <pre><code>CREATE TABLE sales (
    id int(10) unsigned NOT NULL AUTO_INCREMENT,
    uuid varchar(64) NOT NULL,
    firstname varchar(64) NOT NULL DEFAULT '',
    lastname varchar(64) NOT NULL DEFAULT '',
    passport varchar(64) DEFAULT NULL,
    product varchar(64) NOT NULL,
    quantity int(11) DEFAULT NULL,
    cost double DEFAULT NULL,
    paymenttype varchar(64) NOT NULL DEFAULT '',
    paid tinyint(1) DEFAULT NULL,
    tabno varchar(64) NOT NULL,
    createdby int(10) unsigned DEFAULT NULL,
    creationdate datetime DEFAULT NULL,
    modifiedby int(10) unsigned DEFAULT NULL,
    modifieddate timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (id)
  )
  </code></pre>
  
  <p>And the current data</p>
  
  <pre><code>INSERT INTO sales (id, uuid, firstname, lastname, passport, product, quantity, cost, paymenttype, paid, tabno, createdby, creationdate, modifiedby, modifieddate) VALUES
  (20, ':8dcee958-d1ac-6791-6253-0a7344054295', 'Jason', 'Hoff', 'r454545', 'Nicaraguan nachoes', 4, 320, 'credit', 1, '23434', 2, '2010-07-06 04:10:18', 2, '2010-07-06 04:10:18'),
  (19, ':3f03cda5-21bf-9d8c-5eaa-664eb2d4f5a6', 'Jason', 'Hoff', 'r454545', 'Nica Libre (doble 4 o 5 anos)', 1, 30, 'cash', NULL, '35', 2, '2010-07-06 03:35:35', 2, '2010-07-06 03:35:35'),
  (18, ':f83da33b-2238-94b9-897c-debed0c3815e', 'Jason', 'Hoff', 'r454545', 'Helado con salsa de chocolate', 1, 40, 'cash', 1, '2', 2, '2010-07-05 21:30:58', 2, '2010-07-05 21:30:58');
  </code></pre>