I have the following ms access table:
Based on the previous table, I could successfully create a pivot as the following picture shows:
My concern now is: Is it possible to include section column count as further details of dep column?
Results required as the following image:
I appears to be a pivot inside pivot but dont know how to do it. Or, it might be possible by creating report only not pivot query
You can concatenate Unit and Dept for your pivot:
Transform Count(section)
SELECT Unit
From MyTable
GROUP BY Unit
PIVOT (dep & "_" & Unit)
Related
I have a table in a Microsoft Access 2013 database and I want to create a new calculated field that concatenates three lookup fields from this table.
I inserted a new field, defined it as "Calculated" and, using the expression builder, put in the following code:
[Field1] & " " & [Field2] & " " & [Field3]
What I got were numbers, like these:
23423 23 47
How can I get the values instead of the numbers?
See Create or delete a lookup field to create a lookup field in a table. I don't know if you can lookup values in a calculated field in a table. You could try to use the DLookUp function, but event if it works, the performance will be bad. You are better off with creating a query for this purpose.
Something like this
SELECT d.Description, w1.Description & ' ' & w2.Description & ' ' & w3.Description AS sentence
FROM
((dictionary d
LEFT JOIN words w1 ON d.Id = w1.Id)
LEFT JOIN words w2 ON d.Id = w2.Id)
LEFT JOIN words w3 ON d.Id = w3.Id
But it is very difficult to give you a more detailed answer with the very few pieces of information you gave us.
In short, the lookup hides the number that is actually stored in the table. to fix the query, add the look ups manually to your query.
the field with a look up is usually a foreign key to another table. the idea behind a lookup is to show a more intuitive description just like you would with a combobox but the number is still there in the table. the number is just visually wrapped in a combobox:
Hence the query:
gives the result:
To fix this just include the lookup in the query:
which gives the desired result:
In MS access, I have a query that i filter with a list of keywords through a second query. The second select query (which acts as a filter) takes the original (data) query and a keyword table and selects from the data query only the entries that match one of the keywords in the list.
I want to edit a field in the resulting query but access doesnt let me. From what i gather from google & Co. My issue might be caused by not having a relationships between the data query and the keyword table. What can i do to enable editing of the data ? If i were to create a relationship between the keyword table and the data query, how would i design it since 1 keyword does not correspond to one entry in the data query.
Edit: here is the SQL code
Select Sales.saleID, Sales.saleText1, Sales.saleText2, Sales.clientFirstName, Sales.clientLastName, Sales.clientOk
From Sales, Keywords
Where (((Sales.saleText1) Like Keywords!Keyword)) or (((Sales.saleText2) Like Keywords!Keyword));
This returns the correct data but then i cannot edit the clientOk field in the datasheet view (clientOk is a number field)
Thanks in advance for the help
Try something like this:
Select
Sales.saleID, Sales.saleText1, Sales.saleText2, Sales.clientFirstName, Sales.clientLastName, Sales.clientOk
From
Sales
Where
(Sales.saleText1 In (Select [Keyword] From Keywords))
or
(Sales.saleText2 In (Select [Keyword] From Keywords));
My two MySQL tables have different information but one field is common. I am showing you the structure of two tables.
I need to show it in a single report filtering by cust_id.
i.e. Customer Id wise billing and payment report.
I tried...
SELECT * FROM billing_info as a,payment_info as b WHERE a.cust_id='1' AND b.cust_id='1' AND a.cust_id=b.cust_id
but rows are repeating.
Hope I explained this properly. Now what should I do ?
Is it possible in Crystal Report to show two tables data ?
I guess ur table structure may resulting duplicate entries.
in table payment_info instead of using the cust_id (reference of cust table), u should use id of table billing_info so that we will get more precised output for ur query.
U also get payment details agains which bill has been made.
i want to use pivot query using two different table.
i have two table one is GPadvance and second one is GPexpenditure .
i have given advance to gp and get the advance report form the gpadvance. second is whatever the expenduture done by gp it saved in gpexpenditure table. now i want to use pivot table accordingly to GP wise like
you can see the first one data is coming from gpadvance and second column is amount spent data is coming is gpexpenduture.
i want to use single query to use both table data if gp has spent money or not,
iam using the following pivot table for the advance release
select * from
(
select Unit_Name,gpname,isnull(amount,0)as amount,Mcomponent
from AdvGP_report
where unit_id='7' and year='2014-15' and quarter='4'
) as s
pivot
(
sum(amount) for mcomponent in("1","2","3")
) as a
and second pivot query for amount spent is
(
select isnull(financialtarget,0)as FT,MinorComponent_Id
from GPWDPMPR
where unitid='7' and mpryear='2014-15'
) as i
pivot
(
sum(FT) for MinorComponent_Id in("19","4","8")
) as b
its giving the result but repeated many times the amount.
This site has been super helpful with this database i am creating for work, i have a lot of VB knowledge but little SQL.
i am creating a database of cisco IP phones which records the MACs, serials and to what site id they are assigned to.
My managers have now decided to change the goal posts of my application once again and are now asking for me to create a form that displays data in a way i have no idea how to do.
what they now want and what i am hoping to achieve somehow is to create a sql statement that gets the count of the number handsets by site id and then to compare that number against the data from another table.
Here is the fields that we need to work with:
TABLE 1
Handset_Type
Handset_Site_Id
TABLE 2
Handset_Type
Handset_Site_Id
This is how i would like to display the data
SITE ID | Handset_Type1 | Handset_Type1
Handset_Site_id1 |COUNT TYPE1 FROM T1|COUNT TYPE1 FROM T2
Handset_Site_id2 |COUNT TYPE1 FROM T1|COUNT TYPE1 FROM T2
If we can use the data in the Handset_type field to create the column headings then that would be great as there are only a few models of phones but if they are static columns then that will be ok also.
I hope i have explained this ok as i can see this may be complex to understand.
if you have any suggestions please let me know
Thank you
Steve
If I understand the question correctly, you would like to present the count of records from both tables, with the handset type and source table as column headings, for each site ID.
The first step is to merge your tables into a single table, creating a column which expresses the handset type and source table:
SELECT Handset_Type & " in T1" as TypeFromT, Handset_Site_Id FROM [Table 1]
UNION ALL
SELECT Handset_Type & " in T2" as TypeFromT, Handset_Site_Id FROM [Table 2]
This will form an inner query for the crosstab. The syntax for crosstabs can be a bit tricky so I usually build mine in design view. We define the TypeFromT as our new column heading and we use Handset_Site_Id both as our row groupings and as our counting field:
TRANSFORM Count(SubQry.Handset_Site_Id) AS SiteIDCount
SELECT SubQry.Handset_Site_Id
FROM (
SELECT Handset_Type & " in T1" as TypeFromT, Handset_Site_Id FROM [Table 1]
UNION ALL
SELECT Handset_Type & " in T2" as TypeFromT, Handset_Site_Id FROM [Table 2]
) AS SubQry
GROUP BY SubQry.Handset_Site_Id
PIVOT SubQry.TypeFromT;
The only catch is that if there are zero entries for the particular Handset Type, Source Table, and Site ID, the resulting value will be null instead of a 0. If that is undesirable, replace Count(SubQry.Handset_Site_Id) with Nz(Count(SubQry.Handset_Site_Id),0)