Skip to content

Instantly share code, notes, and snippets.

@jgrar
Created December 15, 2013 05:49
Show Gist options
  • Save jgrar/7969406 to your computer and use it in GitHub Desktop.
Save jgrar/7969406 to your computer and use it in GitHub Desktop.
SELECT
sum(Total) AS Total, State
FROM (
SELECT
State, Total
FROM
WorkOrders
INNER JOIN
Customers ON CID = ID
WHERE Type != "Warranty"
UNION
SELECT
State, 80
FROM
WorkOrders
INNER JOIN
CustomersRetail ON CID=ID
WHERE Type = "Warranty"
)
GROUP BY State;
@jgrar
Copy link
Author

jgrar commented Dec 27, 2013

CREATE TABLE "WorkOrders" (
    "WID" integer not null primary key autoincrement,
    "CID" integer,
    "Type" varchar(255),
     "Total" integer
);

CREATE TABLE "Customers" (
    "ID" integer not null primary key autoincrement,
    "State" varchar(255)
);

CREATE TABLE "CustomersRetail" (
    "ID" integer not null primary key autoincrement, 
    "State" varchar(255)
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment