sql - SQLITE: Create View to multiple tables via index -
presently writting bit of code logging requests sqlite database. database not bloated using different tables containing invariant data(apps
,machineid
,ips
, platforms
) can appear lot of times, unique , main table (access
) keeps references on rows in other tables ids. want create view shows main data other tables instead of indexes other tables.
example tables:
apps table ---------- id application buildnum 1 app1 24.112 2 app2 24.113 machineid table -------------- id machineid 1 12345 2 1235 ips table --------- id ip 1 192.168.9.53 platforms table --------------- id platform os 1 windows win7 2 windows win8 access table ------------ date ip_id machineid_id platform_id application_id responsecode 1391677790.7363 1 1 1 1 404 1391677797.5792 1 1 1 1 404 1391677800.7379 1 2 2 2 404 1391677802.493 1 2 2 2 404 1391677889.7193 1 1 1 1 404 1391677890.6034 1 2 2 2 404
now create view looks this:
date ip machineid platform os application buildnum responsecode 1391677790.7363 192.168.9.53 12345 windows win7 app1 24.112 404 1391677797.5792 192.168.9.53 12345 windows win7 app1 24.112 404 1391677800.7379 192.168.9.53 1235 windows win8 app2 24.113 404 1391677802.493 192.168.9.53 1235 windows win8 app2 24.113 404 1391677889.7193 192.168.9.53 12345 windows win7 app1 24.112 404 1391677890.6034 192.168.9.53 1235 windows win8 app2 24.113 404
any clues on how sqlite. sorry if might novice question, not familiar sql.
here code setting example tables:
begin transaction; create table ips (id integer primary key,ip text not null unique); insert "ips" values(1,'192.168.9.53'); create table platforms (id integer primary key,platform text not null,os text not null, unique(platform,os)); insert "platforms" values(1,'windows','win7'); insert "platforms" values(2,'windows','win8'); create table apps (id integer primary key,application text not null,buildnum text not null, unique(application,buildnum)); insert "apps" values(1,'app1','24.112'); insert "apps" values(2,'app2','24.113'); create table machineids (id integer primary key,machineid text not null unique); insert "machineids" values(1,'12345'); insert "machineids" values(2,'1235'); create table access (date real primery key default ((julianday('now') - 2440587.5)*86400.0),ip_id integer not null,machineid_id integer,platform_id integer,application_id integer,responsecode integer); insert "access" values(1391677790.7363,1,1,1,1,404); insert "access" values(1391677797.5792,1,1,1,1,404); insert "access" values(1391677800.7379,1,2,2,2,404); insert "access" values(1391677802.493,1,2,2,2,404); insert "access" values(1391677889.7193,1,1,1,1,404); insert "access" values(1391677890.6034,1,2,2,2,404); commit;
thanks help!
select access.date, ips.ip, machineids.machineid, platforms.platform, platforms.os, apps.application, apps.buildnum, access.responsecode access left join ips on access.ip_id = ips.id left join machineids on access.machineid_id = machineids.id left join platforms on access.platform_id = platforms.id left join apps on access.application_id = apps.id
Comments
Post a Comment