Performing a query on a result from another query?

Usually you can plug a Query’s result (which is basically a table) as the FROM clause source of another query, so something like this will be written: SELECT COUNT(*), SUM(SUBQUERY.AGE) from ( SELECT availables.bookdate AS Date, DATEDIFF(now(),availables.updated_at) as Age FROM availables INNER JOIN rooms ON availables.room_id=rooms.id WHERE availables.bookdate BETWEEN ‘2009-06-25’ AND date_add(‘2009-06-25’, INTERVAL 4 DAY) … Read more

How do I speed up counting rows in a PostgreSQL table?

For a very quick estimate: SELECT reltuples FROM pg_class WHERE relname=”my_table”; There are several caveats, though. For one, relname is not necessarily unique in pg_class. There can be multiple tables with the same relname in multiple schemas of the database. To be unambiguous: SELECT reltuples::bigint FROM pg_class WHERE oid = ‘my_schema.my_table’::regclass; If you do not … Read more

Count the uppercase letters in a string with Python

You can do this with sum, a generator expression, and str.isupper: message = input(“Type word: “) print(“Capital Letters: “, sum(1 for c in message if c.isupper())) See a demonstration below: >>> message = input(“Type word: “) Type word: aBcDeFg >>> print(“Capital Letters: “, sum(1 for c in message if c.isupper())) Capital Letters: 3 >>>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)