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;
Related
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 this column called location in a table called raw_data. Each row have lots of varchar data separated by [, ]. Examples
Row 1 dusseldorf, kjsbdfygs4, Germany
Row 2 768768745h, kiev, Ukraine
Row 3 %%%%666, Accra, Ghana
Yes some make no sense. Im trying to select the last part of the string which is the country and display it.
I tried using the substring index query and understand how it works but cant seem to understand how to apply it to a column.
You can use as per below-
SELECT SUBSTRING_INDEX(my_column,',',-1) FROM raw_data;
Note: If you need 1st part then use only 1 instead of -1.
use like this
SELECT SUBSTRING_INDEX(location ,',',2);
go to below link for explanation
http://www.w3resource.com/mysql/string-functions/mysql-substring_index-function.php
I have a table with some hierarchical data in it. I've handled ordering it in a hierarchical way via calculating the path with a trigger but now I wanna sort them with another parameter too.
Take a look at these pictures:
This Is The Table With Hierarchical Data Ordered By Path:
I Expect These Two Rows To Swap Because Row ID = 4 Has A Date Before Row ID = 2:
So How Can I Order Each Level By Date Column?
NOTE:
The ID Is A Random Number Generated By A TRIGGER.
You can use FIND_IN_SET so as to extract the hierarchy level of each row. Then use this in the ORDER BY clause:
SELECT ID, Name, ParentId, Date, Path
FROM mytable
ORDER BY FIND_IN_SET(ID, REPLACE(Path, '.', ',')), Date
Note: We have to use REPLACE function to replace '.' characters with ','
so that FIND_IN_SET works as expected.
Demo here
Alternatively you can modify your trigger so as to generate an additional 'level' field and use this field in the ORDER BY clause of your query.
I think you have to add the date in the path-column on each level, since you cannot simply order by date.
So the path-column should look something like this:
0.date-2015-12-09 22:15:12.parent1.date-2015-12-09 22:15:14.parent4
0.date-2015-12-09 22:15:12.parent1.date-2015-12-09 22:15:17.parent2
In that case, date superceeds the parent-level.
In this situation 1.4 would appear before 1.2, because 1.4 happend before 1.2
The path-column does get a little lengthy, but its the only way you can incorporate your own hierachy, I think
Did I get it this time? :-)
Hope I could help :-)
I have a table in sqlite that contains roughly about 3 billion values (a lot of them will be repeats). It's basically a giant vector of values. I'm trying to calculate the frequency in which values appear in the table by performing this:-
SELECT abs(diffs), count(*) as total FROM mzdiff GROUP by abs(diffs);
abs(diffs) is the name of my column and mzdiff is my table name, but when I try performing the code above it comes up with an error message saying that the column diffs doesn't exist. I know that the naming of my column isn't really ideal for sql, but is there any way I can get around this?
Thanks
The answer to this is not an alias since the column name must be identified before it can be aliased so use the backtick to quote the name and make it a habit to always quote identifiers.
SELECT `abs(diffs)`, count(*) as total FROM `mzdiff` GROUP by `abs(diffs)`;
Please suggest me an SQL Query for the Below
I have Ids of Items Stored in one column like this 1,2,3,4 as Delimited or CSV value.
Now i want count no of items in one particular row in one particular cell.
i.e
If i have 25,45,26,45,46 in a cell in table.
I want the output like 5 which is nothing but the number of items in a row in a cell say (0,0).
Thank you so much for your Replies
Assuming you don't have values like '123,123,' (note the comma at the end) this should work:
SELECT
LENGTH(yourColumn) - LENGTH(REPLACE(yourColumn, ',', '')) + 1 AS numberOfItemsInRow
FROM yourTable;
Find more information here.
But it would really be better to normalize your database!