sql - Access query - add column with subquery counter -


i need add proper "needcounter" column code query in access. should count rows 1 "worksperweekcounter" shown in last, yellow column. or better 0 "worksperweekcounter-1" :)

i find code wrong because "counter" not correspond "countermin"

let's have table [works(roboczy)], , first 4 columns below [http://i.stack.imgur.com/mto53.jpg][picture] shows. (sorry, reputation low show pictures)

this access query code use (week2date function in vba code):

select        w.id_work, w.id_pracownika, w.vecka, w.rok,     week2date(w.vecka,w.rok) datawk,     c.countworksperweek worksperweekcounter,     c.id_workmin id_workmin,     (w.id_work- c.id_workmin) adddays,     dcount([id_work],"[works(roboczy)]","id_work<=" & [id_work]) counter,     c.countermin [works(roboczy)] w inner join  ( select count(id_work) countworksperweek, id_pracownika, vecka, rok, min(id_work) id_workmin, min(dcount([id_work],"[works(roboczy)]","id_work<=" & [id_work])) countermin     [works(roboczy)]     group id_pracownika, vecka, rok ) c on w.id_pracownika = c.id_pracownika , w.vecka = c.vecka , c.rok = w.rok group w.id_pracownika, w.vecka, id_work, w.rok, week2date(w.vecka,w.rok), c.countworksperweek, c.id_workmin, c.countermin 

you can use series of subqueries in 1 step:

select w.id_work, w.id_pracownika, w.vecka, w.rok, w.datawk,  (select count(w2.rok) workcounter w2  w2.vecka = w.vecka group w2.vecka) worksperweekcounter,  (select min(w3.id_work) workcounter w3  w3.vecka = w.vecka group w3.vecka) id_workmin,   w.id_work -  (select min(w3.id_work) workcounter w3  w3.vecka = w.vecka group w3.vecka) adddays,  (select count(*) workcounter w4  w4.id_work <= w.id_work , w4.vecka = w.vecka) counter  [works(roboczy)] w 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -