SQLite Select data where the column name contains a string?
Since SQLite 3.16, you can use PRAGMAs in queries:
SELECT name
FROM pragma_table_info('MyTable')
WHERE name LIKE ...
How to do arithemtic operations with an alias in sqlite
You don't even need a subquery here:
SELECT
a.albumid,
a.title,
COUNT(t.albumid) AS tracks_count,
COUNT(t.albumid) * a.album_nr AS other_count
FROM albums a
LEFT JOIN tracks t
ON a.albumid = t.albumid
GROUP BY
a.albumid,
a.title;
If you wanted to make your current approach work, then the problem you are having is that you are referring to the tracks_count
alias in the same select in which it was defined. This isn't allowed, because the alias may not have even been computed yet. But, I would recommend using the answer I gave above.
SQLite: Table alias not found when trying to create a new table from a join of two select statements
Wrapping your queries in SELECT * FROM (...)
is causing the problem, because you can't refer to aliases in a subquery.
SELECT t1.story_id, t1.role_type, t1.user_id, t2.workstream_num
FROM (
SELECT story_id, role_type, user_id
FROM cur_cycle_role_activity) AS t1
LEFT JOIN (
SELECT story_id, workstream_num
FROM cur_cycle_role_activity) AS t2
ON t1.story_id = t2.story_id
Are there any restrictions on Postgres column alias names?
The rules for a column alias are no different to than those for regular column names.
http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
SQL identifiers and key words must begin with a letter (a-z, but also letters with diacritical marks and non-Latin letters) or an underscore (_). Subsequent characters in an identifier or key word can be letters, underscores, digits (0-9), or dollar signs ($). Key words and unquoted identifiers are case insensitive.
There is a second kind of identifier: the delimited identifier or quoted identifier. It is formed by enclosing an arbitrary sequence of characters in double-quotes ("). Quoted identifiers can contain any character, except the character with code zero.
Related Topics
Good Embedded Database Solution (Like Sqlite) for .Net
Select Data from Multiple Tables
How to Select Row with Max Value When Duplicate Rows Exist in SQL Server
How to Add Months to a Current_Timestamp in Sql
Oracle SQL Developer 3.1.07 Extra Spaces Between Characters Using Listagg
Postgres Unique Multi-Column Index for Join Table
Finding The Decade with Largest Records, SQL Server
How to Have Temp Tables in a Function
How to Access Latest Row for Each Individual Identifier
Insert Large Amount of Data Efficiently with Sql
How to Relate 3 Tables Depending on Event
What Is The Meaning of Kanatype Sensitive Ks and Width Sensitive
Oracle SQL Merge to Insert and Delete But Not Update
Confusing Error About Missing Left Parenthesis in SQL Statement
Get Only Date Without Time in Oracle
Sql Server Management Studio 2008 Scheduled Export to Ms Access