Currently, running the code down below. However as the field DDMProcess_Merged is a long text, when I use distinct, the input gets cut off. Before using distinct, the input does not get truncated. However, there will be repeats of the records which I do not want. To better visualise the issue, the tables are below.
SELECT DISTINCT DD_MASB.ProcessM_ID,
CONCATRELATED("[DDM]","DD_MASB","ProcessM_ID = " & [ProcessM_ID]) AS DDMASB_Merged,
CONCATRELATED("[DDM_Process]","DD_MASB","ProcessM_ID =" & [ProcessM_ID]) AS DDMProcess_Merged
FROM DD_MASB;
Is there any solution to solve this?
Original Table query (without distinct):
ProcessM_ID
DDMASB_Merged
DDMProcess_Merged
1
x
z
1
x
z
1
x
z
2
y
a
Related
Below is my query from which I'm excluding some characters from query. It's working for me.
SELECT
b.TRANS_DETAILS_ID,
b.DEBIT_AMOUNT,
b.ENTITY_NAME,
REPLACE(b.DESCRIPTION, 'SP Z O.O.', '') AS DESCRIPTION,
DATE_FORMAT(a.TRANSACTION_DATE_TIME, '%d-%m-%Y') AS TRANS_DATE
FROM bank_book_transaction_master a,
bank_book_transaction_details b
WHERE a.TRANSACTION_DATE_TIME
BETWEEN '$from_date_srch' AND '$to_date_srch'
AND DEBIT_CREDIT_FLAG = 2
AND a.ORG_ID = '$org_id'
AND a.BANK_ID = '$bank_id'
AND a.TRANSACTION_ID = b.TRANS_MASTER_ID
But my problem is in my database SP Z O.O. these characters are storing differently sometimes. In some columns it's SP Z O.o. or sp z O.O. or SP Z O.O.. My query removes only if charaters are similar like SP Z O.O.. But I want to add all conditions like small letters whitespace etc.
I tried with LIKE %SP Z O.O.% but it shows me result in 1 and 0.
I have a database that lists a few area codes, area code + office codes and some whole numbers and a action. I want it to return a result by the digits given but I am not sure how to accomplish it. I have some MySQL knowledge but its not very deep.
Here is a example:
match | action
_____________________
234 | goto 1
333743 | goto 2
8005551212| goto 3
234843 | goto 4
I need to query the database with a full 10 digit number -
query 8005551212 gives "goto 3"
query 2345551212 gives "goto 1"
query 3337431212 gives "goto 2"
query 2348431212 gives "goto 4"
This would be similar to the LIKE selection, but I need to match against the database value instead of the query value. Matching the full number is easy,
SELECT * FROM database WHERE `match` = 8005551212;
First the number to query will always be 10 digits, so I am not sure how to format the SELECT statement to differentiate the match of 234XXXXXXX and 234843XXXX, as I can only have one match return. Basically if it does not match the 10 digits, then it checks 6 digits, then it will check the 3 digits.
I hope this makes sense, I do not have any other way to format the number and it has to be accomplished with just a single SQL query and return over a ODCB connection in Asterisk.
Try this
SELECT match, action FROM mytable WHERE '8005551212' like concat(match,'%')
The issue is that you will get two rows in one case .. given your data..
SELECT action
FROM mytable
WHERE '8005551212' like concat(match,'%')
order by length(match) desc limit 1
That should get the row that had the most digits matched..
try this:
SELECT * FROM (
SELECT 3 AS score,r.* FROM mytable r WHERE match LIKE CONCAT(SUBSTRING('1234567890',1,3),'%')
UNION ALL
SELECT 6 AS score,r.* FROM mytable r WHERE match LIKE CONCAT(SUBSTRING('1234567890',1,6),'%')
UNION ALL
SELECT 10 AS score,r.* FROM mytable r WHERE match LIKE CONCAT(SUBSTRING('1234567890',1,10),'%')
) AS tmp
ORDER BY score DESC
LIMIT 1;
What ended up working -
SELECT `function`,`destination`
FROM reroute
WHERE `group` = '${ARG2}'
AND `name` = 0
AND '${ARG1}' LIKE concat(`match`,'%')
ORDER BY length(`match`) DESC LIMIT 1
Hey is there any way to create query with simple formula ?
I have a table data with two columns value_one and value_two both are decimal values. I want to select this rows where difference between value_one and value_two is grater then 5. How can i do this?
Can i do something like this ?
SELECT * FROM data WHERE (MAX(value_one, value_two) - MIN(value_one, value_two)) > 5
Example values
value_one, value_two
1,6
9,3
2,3
3,2
so analogical difs are: 5, 6, 1, 1 so the selected row would be only first and second.
Consider an example where smaller number is subtracted with a bigger number:
2 - 5 = -3
So, the result is a difference of two numbers with a negation sign.
Now, consider the reverse scenario, when bigger number is subtracted with the smaller number:
5 - 2 = 3
Pretty simple right.
Basically, the difference of two number remains same, if you just ignore the sign. This is in other words called absolute value of a number.
Now, the question arises how to find the absolute value in MySQL?
Answer to this is the built-in method of MySQL i.e. abs() function which returns an absolute value of a number.
ABS(X):
Returns the absolute value of X.
mysql> SELECT ABS(2);
-> 2
mysql> SELECT ABS(-32);
-> 32
Therefore, without worrying about finding min and max number, we can directly focus on the difference of two numbers and then, retrieving the absolute value of the result. Finally, check if it is greater than 5.
So, the final query becomes:
SELECT *
FROM data
WHERE abs(value_one - value_two) > 5;
You can also do complex operations once the absolute value is calculated like adding or dividing with the third value. Check the code below:
SELECT *
FROM
data
WHERE
(abs(value_one - value_two) / value_three) + value_four > 5;
You can also add multiple conditions using logical operators like AND, OR, NOT to do so. Click here for logical operators.
SELECT *
FROM
data
WHERE
((abs(value_one - value_two) / value_three) + value_four > 5)
AND (value_five != 0);
Here is the link with various functions available in MySQL:
https://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html
No, you would just use a simple where clause:
select *
from data
where abs(value_one - value_two) > 5;
I have following query
strfinal = "
TRANSFORM Format(Sum([Mandays].[Hours]),""#0.0"") AS [The Value]
SELECT
Mandays.WorkTypeCode AS WONo,
Format(Sum([Mandays].[Hours]),""0000.0"") AS Total
FROM Mandays
GROUP BY Mandays.WorkTypeCode
PIVOT UCase([Ent By]); "
the query returns more than 2048 records and then it is not possible to show in VB6 MSHFLexGrid(Limit is 2048).
How do I change query so that top 2000 records must be fetched?
The most efficient way will be to do it like this:
CurrentDB.CreateQueryDef("tmpQuery", "SELECT Top 2000 * FROM Mandays")
strfinal = "TRANSFORM Format(Sum([tmpQuery].[Hours]),""#0.0"") AS [The Value]
SELECT tmpQuery.WorkTypeCode AS WONo, Format(Sum([tmpQuery].[Hours]),""0000.0"") AS
Total FROM tmpQuery GROUP BY tmpQuery.WorkTypeCode PIVOT UCase([Ent By]); "
You could put "Top 2000" after the SELECT statement in your current code, but doing it in another query will speed things up quite a bit.
If you like, you can also put an ORDER BY statement in the CreateQueryDef so you can control which 2000 records are used.
If my answer is in another post, I've not found it. A post I thought might have my answer was
"I want to concatenate 2 strings from 2 textareas and insert them into a column in my table."
I am converting some data. Other database has text that is stored in the same table, different fields. each field (x.description_plain_text has a sequence number as illustrated in the script. As you can maybe see with my attempt, I would like to bring both of the text lines into one (varchar(8000)) field and separate with a line or two. I don't know if I am allowed to tag a second objective, but if/after I get these separate lines from the other database into one field in my new database I then want to be able to put an identifier next to each ... as I am trying to show in the 2nd illustration ...
1st illustration
--select x.description_plain_text, x.SEQ_NO
update MIC.dbo.Item set CustomerDocumentNote =
case
when x.SEQ_NO = 1 then cast(x.description_plain_text as varchar(8000))
when x.SEQ_NO = 2 then cast(x.description_plain_text as varchar(8000))
END
-- x.description_plain_text + CHAR(13) + CHAR(10) + cast(x.description_plain_text as varchar (8000))
from MIC.dbo.Item a
inner join in_item_xdesc x on x.item_id = a.itemid
where (a.ItemNumber = '14661')--(IS_PRINT_ACKNOW = 'Y' and SEQ_NO = 2)
2nd illustration ... need a SQL query that will give me just the description with P_A ... P_A is merely an identifier ... can be anything ... just a way to say If P_A then print but IF
P_PT_PO THEN print ...
P_A - Heater with 1.5" OD flange at 2.5", 48" mica leads with 36" SS braid exiting 90° from sheath, single clip support. 800 Watts & 240 Volts. For Gala pellitizer.
+ CHAR(13) +
P_PT_PO - Stamp "MIC #14661" on OD of heater. Silicone over Cement at lead ends.