For the below `bank' schema: customer(customerid,username,fname,lname,street1,street2,city,state,zip) account(accountid,customerid,description,) transaction(transactionid,trantimestamp,accountid,amount) A customer may have several accounts, and each account may participate in many transactions. Each transaction will have at least two records, one deducting amount from an account, and one adding amount to an account (for a single transactionid, the sum of amounts will equal zero). Using SQL, answer these questions (write a SQL query that answers these questions):
8) List the top 1% of customers (ordered by total balance).
9) Using balances for previous two months, predict what the balances will be next month. (tip: find slope of a line; x-axis is days, y-axis is balance. 2 previous months means you have 2 points, finding slope is easy. Use slope to predict where next month's balance will be.)
select Top round(custcount*0.01,1) customerid, username from (
select c.customerid,c.username,count(c.customerid) as custcount from customer c inner join account a on c.customerid=a.customerid inner join transaction t on a.accountid=t.accountid group by c.customerid,c.username order by sum(t.amount)) as subtable;
Tip command to get number of rows from results.custcount*0.01 gives 1% and round will do rounding to upper value.
as per HomeworkLib rules we can only solve 1 questions per post
For the below `bank' schema: customer(customerid,username,fname,lname,street1,street2,city,state,zip) account(accountid,customerid,description,) transaction(transactionid,trantimestamp,accountid,amount) A customer may have several accounts, and each...
For the below questions, use the following schema definition. customer(custid,lname,fname,street,city,state,zip,dob) device(devid,custid,type) device_onoff(ts,devid,pwr) device_chnl(ts,devid,chnl) schedule(start_ts,end_ts,chnl,showid) This is a schema for a tv network. Customers own devices (of a certain type; phone is a device, cable-box is a device, etc.), and they can watch channels on those devices. Whenever a device comes online, we get a device onoff event, indicating device power state. Whenever a device channel changes, we get a device chnl event. There is also a schedule object, which tells...