sql - Use cid in sqlite instead of column name? -


when creating view, name assigned column not usable in sqlite, in order perform specific operation afterwards. instance, created following view:

create view myview    select amount, count(name), name      mytable  group name    having count(name) > 1; 

then following operation:

select total(amount*count(name))   myview; 

unfortunately, count(name) name given sqlite second column, hence, cannot used in select statement. pragma table_info(myview) shows cid count(name) 1, there anyway use information able computation on column?

you need define column alias:

create view myview    select amount,           count(name) name_count,           name      mytable  group name    having count(name) > 1; 

then, you'll able use:

select sum(v.amount * v.name_count)   myview v; 

i changed out total sum, more consistent other databases (sqlite aggregate functions).


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -