Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
SELECT r1.rnr, r1.anaam
FROM regisseur r1, regisseur r2
WHERE r2.anaam = <'input last name director'>
AND r1.gdatum < r2.gbdatum
can someone change this to an Oracle SQL query really having difficulty with it, and it shouldnt be this hard.
All you need to do is remove the < and > characters:
SELECT r1.rnr, r1.anaam
FROM regisseur r1, regisseur r2
WHERE r2.anaam = 'input last name director'
AND r1.gdatum < r2.gbdatum
Here's a working demo on SQLFiddle.
Presuming you don't have a good reason to SELECT from regisseur twice, this can be further condensed down to:
SELECT rnr, anaam
FROM regisseur
WHERE anaam = 'input last name director'
AND gdatum < gbdatum
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I ask myself why this request
SELECT * FROM world.city WHERE '20181109' > datedebut and '20181109' < datefin;
doesn't return the same result as this
SELECT * FROM world.city WHERE datedebut < 20181109 < datefin;
The last select sentence is not valid SQL, but mathematically it is the optimal solution
For each operator (ie < or > ) there must be a distinct right and left side.
When you write datedebut < 20181109 < datefin it is parsed as datedebut < 20181109 and the result of that comparison is sent to the next operator.
You need to think differently when writing SQL than when writing mathematics. You can argument that both "languages" have parsers, but they are slightly different.
EDIT comment:
As I have been made aware in the comments, My original answer was not entirely correct, since that would ave given a parse error. The essence is correct: Your query is not being parsed as you expected.
As others have answered, if you want a more compact answer, you need to use the BETWEEN keyword instead of the <and > operators.
There is a MySQL expression syntax which more closely matches your second form, which is BETWEEN:
SELECT * FROM world.city WHERE '20181109' BETWEEN datedebut AND datefin
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my database table have this value,i have to check this email value 'abc#gmail.com' is exist in the database or not.
abc#gmail.com
edf#dfg.com
xyz#abcinfo.com
12345#fdfg.com
If 'abc#gmail.com' value is exist in the database table, output is true else false, so how to write the query for this to achieve?
thanks
Kumar
You can do something as simple as
select CASE WHEN count(1) > 0 THEN 'true' ELSE 'false' END from table where email = 'abc#gmail.com'
But you should give some more information for a beater answer.
you can write query like
SELECT IF(COUNT(*) >0, TRUE,FALSE)as response FROM <tablename> WHERE emailid='edf#dfg.com';
select exists(
SELECT 1 FROM <tableName> WHERE email LIKE 'abc#gmail.com'
)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I converted phpbb2 forum to phpbb3.
But I have problem with phpbb2 posts links which remained in MySQL database.
phpbb2 posts links are eg.
/viewtopic.php?p=106352#106352
and phpbb3 are:
/viewtopic.php?p=106352#p106352
(there is letter p after #)
Current links from phpbb2 are not working, after convert,
so I need help replacing # between posts id (numbers) in MySQL DB.
I got a lot of links like:
/viewtopic.php?p=106352#106352
and I need to replace # with p ( add p at the end)
like:
/viewtopic.php?p=106352#p106352
I don't know much MySQL, so I stuck.
Please help
One possible approach:
UPDATE phpbb_posts
SET post_text = REPLACE(post_text, '#', '#p')
WHERE post_text REGEXP '^[^#]*p=[0-9]+#[0-9]+$'
WHERE clause is specified to prevent updating links that do not follow the format.
SQL Fiddle.
select replace('/viewtopic.php?p=106352#106352','#','#p')
update myTable
set myColumn = replace(myColumn, '#', '#p')
where someColumn = someThing
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a huge table I'm trying to port to a new database, there's a row that stores number of doors, body style, and gearbox like "4SDa" for 4 door sedan, auto or "5HBm" for 5 door hatchback, manual.
I need to select all rows that AREN'T like this so I can edit them as they are causing issues.
How can I select any row that isn't in the format
number-letter-letter-letter' (case insensitive)
select * from your_table
where your_column not regexp '^[0-9][a-zA-Z]{3,3}$'
Regex Tester
SELECT '4SDa' REGEXP '^[0-9][a-z]{3}$'; --> 1
SELECT '4SDaa' REGEXP '^[0-9][a-z]{3}$'; --> 0
SELECT 'AAbb' REGEXP '^[0-9][a-z]{3}$'; --> 0
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to do a simple count of the CPT codes and am confused on why I am getting the error:
Msg 245, Level 16, State 1, Line 3
Conversion failed when converting the varchar value 'J1040' to data type int.
Here is the query:
SET NOCOUNT ON
SELECT
count(pvp.CPTCode) as CPTcount
from
PatientVisitProcs pvp
JOIN batch b ON pvp.batchid = b.batchid
JOIN patientvisit ar ON pvp.patientvisitid = ar.patientvisitid
WHERE
b.Entry >= ISNULL('09/01/2012','1/1/1900') and b.Entry < dateadd(d, 1, ISNULL('8/31/2012','1/1/3000'))
and pvp.CPTCode in (62311,64484,64493,64494,62310,64479,64480,64490,64491,64492,64633,64634,64635,64636)
AND --Filter on company
(
( ar.CompanyID IN (1725))
)
AND --Filter on facility
(
( ar.FacilityID IN (1460))
)
Group By pvp.CPTCode
With RollUp
A gentle push or swift kick in the right direction would be greatly appreciated. THanks!
I believe it is coming from the actual CPTCode column:
CPTCode
80053
80061
83721
85025
81001
84153
Copay
Copay
J0152
You have:
pvp.CPTCode in (62311,64484,64493,64494,62310,64479,64480,64490,64491,64492,64633,64634,64635,64636)
But your column type is varchar(n). So try changing it to:
pvp.CPTCode in ('62311','64484','64493','64494','62310','64479','64480'... and so forth