What does this do?
def func(): print 'foo' return yield 'bar' print func()
Take a guess, then give it a try.
def func(): print 'foo' return yield 'bar' print func()
SELECT
UserId,
LastLogin
FROM Users
JOIN (
SELECT
UserId,
DATEDIFF(NOW(), MAX(TimeStamp)) AS LastLogin
FROM Logins
GROUP BY UserId
) AS Temp USING (UserId)
WHERE LastLogin <= 31;
We can convert this to a simple JOIN with the magic of HAVING. HAVING is like WHERE, but applies after aggregation:SELECT
UserId,
DATEDIFF(NOW(), MAX(TimeStamp)) AS LastLogin
FROM Users
JOIN Logins USING (UserId)
GROUP BY UserId
HAVING LastLogin <= 31;
SELECT
CustomerId,
COUNT(CustomerId)
FROM A
WHERE
CustomerId IN (15, 16)
GROUP BY CustomerId;
CREATE TABLE ScratchTable AS
SELECT
CustomerId,
COUNT(CustomerId) AS Customers
FROM A
WHERE
CustomerId IN (15, 16)
GROUP BY CustomerId;
UPDATE A
JOIN ScratchTable USING (CustomerId)
SET Updated=1
WHERE
A.Id=3
AND Customers=1;
INSERT INTO A (CustomerId)
SELECT CustomerId
FROM ScratchTable
WHERE
CustomerId=15
AND Customers=1;
Perhaps A=”Users”, B=”DVDs Owned”, C=”Logins”, D=”Times Watched”, while E=”Administrators” and F=”Changes”. These are two hierarchies, since A and E have no links to each other. Minimizing the number of hierarchies (keeping it to just one is awesome!) makes it easier to shard later. Schemas with cross-links (say F also links to A, or a table records transfers between two different users, linking to A twice) are very difficult to shard.