Is there a way to get a specific row based on a columns value?
Say I have a column 'name' which has a unique value and I want to get an entire row based on that single value. For example, say I have a row defined by three columns 'name' 'city' and 'state' and want to get all three columns associated with that row only using the value 'Jeremy' found in the 'name' column.
I know I can do this by selecting all rows and use if statements to break down the rows to find what I am looking for but I am also sure there must be an easier command through MySQL to achieve this.
Isn't it as simple as this? This is a basic filtering :D
SELECT name, city, state
FROM tableName
WHERE name = 'Jeremy'
Related
I have a table like this:
I want to get distinct row from this. I use:
DB::table('dmspro_mys_campaign_product')->distinct()->get();
But it still give result with 3 rows. I expected 2 rows.
How I can fix this?
Simply pass the field name inside the distinct function. like this(in case if you want distinct based on 'compeign_code' column)
DB::table('dmspro_mys_campaign_product')->distinct('compeign_code')->get();
in case if you want to distinct the field based on more than one column value then you can use the select method.
In my opinion the answer is correct. District rows give you the results where every row is unique. Since there are slight variations between all three rows, you get all three because no row is exactly equal to another row.
I hope I could help,
Sebastian
You need a distinct value from dmspro_mys_campaign_product table so Database query needs pass column name.
DB::table('dmspro_mys_campaign_product')->distinct('product_id')->get();
You simply need to mention the column name in distinct('compeign_code').
DB::table('dmspro_mys_campaign_product')->distinct('compeign_code')->get();
Or you can try
DB::table('dmspro_mys_campaign_product')->groupby('product_id')->distinct()->get();
If you want to get only one column then you may use this.
DB::table('dmspro_mys_campaign_product')->distinct()->select('product_id');
This is the table that I would like to compare the values within the row groups incrementally however I would not like to compare rows amongst groups as it would come with negative values.
How do I achieve this on the same table? I am unfamiliar with subqueries
It sounds like what you need is a Calculated Field added as a third column to your table.
Instructions:
Select the drop down menu next to "Click to Add" to create a new column.
From the choices available select Caluculated Field and then Number.
The Expression Builder will open.
All you need to do from there is select the column you want to use as your primary number (in your case Number) from the Expression Categories, insert a minus sign, then select the number you want to subtract from the first number (in your case Group), again in the Expression Categories.
Name the column you created whatever you would like.
I have a matrix/tablix set up so there are 4 row groups going down the left-hand side and a column group called RegCompCategory:
When the report is run, the RegCompCategory column group produces 3 distinct columns based on the categories in the underlying data:
What I'd like to do is add another column before the RegCompCategory column group that will display a percentage of the "fully-marked" column against the "total" column:
I'm guessing I will need to write an expression for the fields highlighted above, but I'm not sure how to reference the RegCompCategory to identify specifically the "Fully-Marked" category of data.
Could someone give me a few pointers? Many thanks.
Try:
=Count(IIF(Fields!RegCompCategory.Value="Fully-Market",Fields!RegCompCategory.Value,Nothing))
/
Count(Fields!RegCompCategory.Value)
It will count the number of Fully-Market rows and divide by the total rows. I think that is what you are expecting.
Let me know if this helps you.
In the table above there is a column called from_stop and a column called to_stop.
I want to select all from_stop values where from_timing is equal to 'PTP' and select all to_stop values where to_timing is equal to 'PTP', in a single column.
So essentially I should have a column called stop that selects what I've said above.
I have made a few attempts but this query is baffling me because of poor relational set up, I am aware of that but this can't be changed.
Any ideas?
Example results:
stop_column
1900HA030090
1900HA058450
So essentially I have a column of results where the from_timing and from_stop are equal or to_timing and to_stop are equal.
SELECT from_stop FROM <rel_name> WHERE from_timing = 'PTP'
UNION
SELECT to_stop FROM <rel_name> WHERE to_timing = 'PTP'
This will remove all duplicates, if you want to retain duplicates use UNION ALL instead
Ok, I have table called "lookup" which has a column called "name" which contains a bit of data starting with "Quantity for pricing" (the data I need is in the same cell just after Quantity for Pricing). I was wondering if there was any way to pull out that "row", and list all the quantities except for Quantity for Pricing using mysql?
Sorry for the confusion guys, this is what I am dealing with.
I am pretty sure the data I need (the actual quantities) are stored in the same bit that "Quantity for Pricing" is.
You can use substring operation.
SELECT SUBSTRING(name,LENGTH('Quantity for pricing'))
FROM lookup WHERE name LIKE 'Quantity for pricing%';
I think this is what you want:
SELECT REPLACE(name,"Quantity for pricing","") AS name FROM lookup;
This selects all of the rows from the table lookup, returning the value in column name, but excluding the occurence of "Quantity for pricing" in the column value.
You can use REPLACE
SELECT REPLACE(columnToSearch, 'Quantity for pricing ', '') FROM TableToSearch;