Gathering a count of something specific from mysql - mysql

I am trying to gather some specific info from mysql.
Main table is called db_items
Now in db_items there is multiple fields but the one i am focused on is named "types"
Now i want to get the total count of a unique items from that.
There is 5 different types in there. But i just want to focus on the one named "album" How would i do this ?
then also in the same mysql query be able to also grab the last 5 added to the Album field.
So then in php i can just Display the total count of albums. then show the last 5 added.

Related

How to get sum of attributes from different tables MYSQL

I am new to MySQL, currently I've been trying to create a column in a table that contains the total of payment an individual has to pay. For references, the first picture is how I want the tables to look like (in the big picture).
What i want is that in the column of total_to_pay, it automatically sums up the value of price from Mobile_Subscription, value of price from TV_Subscription and value of payment_from_past from History. So I want it to basically look something like this:
I want to know if such thing is possible and if not how can i make something similar?
I searched on Google this problem but all I could find was how to sum all values from 2 different columns, when what I wanted is to sum 2 (or 3) specific values from 2 different column from 2 different tables.

Web Intelligence : limit row number in a block

I have a list of events with a number of orders. I want to only display the first five biggest amount of orders in my report. I created a variable with the rank of each event :
=Rank([Total orders])
Then I created a variable with the five event depending rank but I get this :
=[Event] Where ([Rank]<=5)
I have an empty cell equal to all non displayed results and the sum of commands amounts.
Is there a way to fix that ? If it's not possible how can I rename the empty cell with "Others" label ?
I work on WebI 4.2 Support Pack 4 Compilation : 14.2.4.2410.
I see three different ways to do this. As an example I created a query using the eFashion universe.
You could create a variable like you had and add a filter where MyRank <= 5.
MyRank=Rank([Query 1].[Quantity sold])
You could right-click on your Orders column, choose Ranking > Add Ranking..., and change the value for Top to 5. Leave everything else alone and click OK.
You could database ranking within your query. This option only brings back the data you want. The previous two option bring back more data than you want from the database and then filter it out in the report. This link has some further detail on how to set this up.
Each option has its place. The first one is most like what you have tried. I think the second one is the simplest. And the last one is the most efficient. You choose what is best for you.
Here are my results for each of the three approaches I described in order.

How to show data on Jasper with having more than one rows

Need one help. Suppose:
I have one query which gives 3 rows as output once user submits form.
On the same table 3 rows are generated as owner_details, shipment_details and contact_details. Here I have one foreign key which is same for 3 rows and one unique primary key.
Now I want to print all these 3 rows on Jasper with different owner_details, shipment_details and contact_details.
If you want to use three different section, one for every kind of details, you can design as follow your report.
Create a main report to get your main object (with three rows), so you can define 3 details bands with three different subreports, one for kind of detail.
In every subreport you can pass your collection and in the body of subreport you can discard the rows you don't want to print. So you'll have a report with three different sections and in every section one row. Right?
EDIT
To conditionate your row in detail you can do as follow (sorry but I've italian version, so the name can be different).
Select detail band as follow:
In the property tab you have a field with your print condition, as follow:
Click on 3 points and write your truly condition.
For example, if you have a field category with value ship_detail and you want to show only ship details, you can write as follow:
$F{category} != null && $F{category} == "ship_detail"

Design - Microsoft Access - Unique "Serial" Number

I am looking for some design techniques to achieve the following:
A 3-part serial number that is generated upon record entry. Format Example: 25-001-14
The number is used to track yearly records from various locations.
The first part states the location the record is associated with, this would be a user input during record creation.
The second part is the record number, I would like for this to be automatically generated, but needs to be sequential and separate for each location and needs to reset each year.
The third part is the two digit number for the year the record was created in. I would like this to be automatically generated if possible. Note: I am currently not concerned with when this cycles back around and I face redundant data issues.
I'm thinking I would like records to be stored in multiple tables that are separated by location, if this would help things!
Any ideas would be greatly welcomed.
I think I would use 3 key fields - one field each for location, record and year. The location and year fields would be created when you get the input to create new records. I would set up a query to find the last record number used by location and year and use that query to assign the new record number when you create a new record. The concatenation of the 3 fields would be the key you described.
With a key field for location, separate tables are not necessary unless that's useful for other reasons. I would probably use just one table - you can always filter the records by location anytime you need to.

Single or Multiple IDs for same value but in different states/questions

I have a lookup value "Unread". It is used here:
Mail can be read or unread. (So i have ID 10 = read and ID 11 = unread). Now in the UI I have display filters where i can sort message by predefined filters, one of these is 'Unread' So the question is: Are the IDs in both cases going to be 11 or do i create two separate values for Unread - one for the message state and one for the display sort?
The use of this data is 2 folds:
1) Reference its main action based on the FK lookup ID
2) Reporting: If i want to see how many users sorted using Unread filter for Unread mail, in which case can i get that number easily - by using two IDs (one for each question (message state and display sort) or one ID only?
The status value of read/unread is a property of the message item, not of the GUI or the user. The filter state selected by the user is a property of the user, not the message.
If it makes sense to you to have the same values used in these two similar, but independent code columns, then that is fine.
You need to store the message state as a column on the message (unless you want to track the history of message state, in which case it has to go into a child table of the message). You need to store the current filter selection state for each user on your user table. I can't imagine why you'd want to historize that so a single column on your user table should do the trick.
If unread in the message table is "11" and unread in the user table is also "11" then that's fine, but it's coincidental and you want to be careful about making any assumptions in your code about this. When you start adding in other filter combinations the whole scheme could come crashing down on you unless you're committed to having matched pairs of attributes in your user/gui filter selection table and whatever message attributes line up with your filter options.