dcount in query (1 Viewer)

mohamedmatter

Registered User.
Local time
Today, 00:04
Joined
Oct 25, 2015
Messages
112
query name total of devices in school
table1 filed id, schoolname
table2 filed id-lab ,lab name,device-name;device-kind
i want query count device in lab in school by dcount
error
=dcount("[id-lab]";"[table2]";"[device-name]='tv' and [device-kind]='samsung' and [id-lab]="& [id]) when run query error
any hlp
 

CJ_London

Super Moderator
Staff member
Local time
Today, 08:04
Joined
Feb 19, 2013
Messages
16,610
what is the error that you get?

If this is a query, then you don't need the = before dcount

Also, usual requirement is for a comma, not a semi colon between the dcount parameters, but that can be different depending on the language you are using - however need to ask just to eliminate it as a possible error.

you could just link the two tables on [id-lab]=[id] and use a group by query - something like

Code:
SELECT ID, Schoolname, device-name, device-kind, count(id-lab) as totaldevices
FROM table1 inner join table2 on table2.[id-lab]=table1.[id]
GROUP BY ID, Schoolname, device-name, device-kind
 

mohamedmatter

Registered User.
Local time
Today, 00:04
Joined
Oct 25, 2015
Messages
112
error in bmp
 

Attachments

  • 11.jpg
    11.jpg
    91.7 KB · Views: 40

CJ_London

Super Moderator
Staff member
Local time
Today, 08:04
Joined
Feb 19, 2013
Messages
16,610
assuming you are referencing my last post, you didn't use what I suggested.

if you are using dcount, you don't use a group by query
 

mohamedmatter

Registered User.
Local time
Today, 00:04
Joined
Oct 25, 2015
Messages
112
what is the error that you get?

If this is a query, then you don't need the = before dcount

Also, usual requirement is for a comma, not a semi colon between the dcount parameters, but that can be different depending on the language you are using - however need to ask just to eliminate it as a possible error.

you could just link the two tables on [id-lab]=[id] and use a group by query - something like

Code:
SELECT ID, Schoolname, device-name, device-kind, count(id-lab) as totaldevices
FROM table1 inner join table2 on table2.[id-lab]=table1.[id]
GROUP BY ID, Schoolname, device-name, device-kind
i want this query but devicename and devicekind in heading column
and one row for school A for example
 

mohamedmatter

Registered User.
Local time
Today, 00:04
Joined
Oct 25, 2015
Messages
112
assuming you are referencing my last post, you didn't use what I suggested.

if you are using dcount, you don't use a group by query

i want this query but devicename and devicekind in heading column
and one row for school A for example
 

CJ_London

Super Moderator
Staff member
Local time
Today, 08:04
Joined
Feb 19, 2013
Messages
16,610
not sure what you are asking - the example query I provided does that
 

mohamedmatter

Registered User.
Local time
Today, 00:04
Joined
Oct 25, 2015
Messages
112
not sure what you are asking - the example query I provided does that

I am sorry don’t explain request for you
I attach my file school database my request in query QryByLab
I want correct the formula builder in query to count devciekind = p4 and devicename =computer in Each school separately in this query look for example in this table in this imag
 

Attachments

  • P1.jpg
    P1.jpg
    80.8 KB · Views: 35

CJ_London

Super Moderator
Staff member
Local time
Today, 08:04
Joined
Feb 19, 2013
Messages
16,610
for that layout, change your group by query to a cross tab
 

CJ_London

Super Moderator
Staff member
Local time
Today, 08:04
Joined
Feb 19, 2013
Messages
16,610
provide a database with some test data, the query you are using and what you want as a result based on the test data - use excel to show the required result and I will take a look -probably not today, I have a fairly full day today

ensure the database has been compacted, zip both files and upload the zip file to the forum
 

mohamedmatter

Registered User.
Local time
Today, 00:04
Joined
Oct 25, 2015
Messages
112
provide a database with some test data, the query you are using and what you want as a result based on the test data - use excel to show the required result and I will take a look -probably not today, I have a fairly full day today

ensure the database has been compacted, zip both files and upload the zip file to the forum
the file excel explain the request
 

Attachments

  • school.zip
    26.4 KB · Views: 57

isladogs

MVP / VIP
Local time
Today, 08:04
Joined
Jan 14, 2017
Messages
18,218
Hi
I've done two crosstabs for you.
Neither are laid out exactly as you've shown but you might find them as good or possibly better. If not just adapt as required.
 

Attachments

  • school.zip
    27.7 KB · Views: 35

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:04
Joined
May 7, 2009
Messages
19,241
see query0 uoto query4.
FinalQuery is the result you want but it is not dynamic.
 

Attachments

  • school.zip
    36.1 KB · Views: 46

CJ_London

Super Moderator
Staff member
Local time
Today, 08:04
Joined
Feb 19, 2013
Messages
16,610
arnel means that the structure is fixed - will only work for P4/P5 LabA/LabB and LG/Sumsung, however another school would appear on another line

if you have more then you need to modify the final query to accommodate them.

your requirement and data structure is not really understood (at least by me) - I know LG and Samsung are manufacturers - I presume P4/P5 are a model of computer rather than manufacturer? In which case why not have the LG model etc. It feels like they should be in a separate column or table. And why is device name populated with effectively device types?

why have a column 'P4 in Lab A', but not 'Computer in Lab A' when you have 'TV kind LG' but not 'LG kind TV' - the use of the columns is swapped.

And why have an output like this anyway? there are perhaps better ways of doing it (the concatrelated function comes to mind). But without knowing the purpose there is no point in suggesting it.
 

isladogs

MVP / VIP
Local time
Today, 08:04
Joined
Jan 14, 2017
Messages
18,218
Expanding on CJ_London's reply, in my earlier answer I gave you two crosstabs where the column headers were dynamic. In other words they would have automatically updated if you added a Sony TV or similar.

Arnelgp gave you exactly what you asked for but that means if you added new items, the columns wouldn't necessarily show them.
 

Users who are viewing this thread

Top Bottom