How can I search Product name with minimum query SQL
id product-name
---------------------
1 VFD 1.0HP, 3PHASE VFD2A7MS43ANSAA
2 Cable Flex. PVC 1 core 0.75sq mm Y/G 200m
3 Cable Flex. PVC 1 core 0.75sq mm White 200m
4 Cable Flex. PVC 1 core 0.75sq mm Blue 90m
if I do search with Product name for id 3 - 'flex 1 core cable'.
select *
FROM product
where product-name like '%flex%1%core%cable%'
it does not working properly
if I have search left to right with random word taken---its work properly but if choose word right to left its not fetching data.....
thanks
you can try using different like clauses, so their position won't matter but they'll all be included, example;
select * FROM product where product-name like '%flex%' and product-name like '%1%' and product-name like '%core%' and product-name like '%cable%'
Related
I am very new to Microsoft reporting. I have a table and I need to show the Category Name and the count how many times the category existed in the report so for e.g, I have the following:
CategoryName Id
Normal 1
High 2
Normal 3
Low 4
Normal 5
Normal 6
Normal 7
Normal 8
Low 9
Low 10
Low 11
High 12
I want to display something like this:
Category Count
Normal 6
Low 4
High 2
I was able to display the category ( Normal, Low and High) and the associated count with the category. The problem is, I cannot put the title "Category" and "count" at the top because I put the CategoryName and count in the header column and I deleted the data column like I showed in the image below. How can I put the title in the above table.
The image after adding the group filed looks like this:
any help will be greatly appreciated.
Your Problem:
Category and Count as Title of your Tablix.
It's pretty easy. Just go to you Header Click on Cell where you wish to put Category.
You can write Category just like a TextBox
I am trying out Access for the first time and I am trying to figure out how to really harness the amazing power of Access.
With that, I want to find the average quantity of each item but do not know how to do that. I set up 2 tables. One is the list of items (sand, water, etc.) then set up a relationship to another table that put out the quantities and price.
Below, Query 1 I set up and sorted it (I don't know why it isn't alphabetical even though I sorted ascending, but thats not why I'm here). So could someone help me try and figure out how to average each items amounts like in Query 2? Ultimately, I really just want the query to find the MaxAve and the MinAve and just show those 2 like in Query 3 below.
Query 1 Query 2 Query 3
fldName fldNum fldName fldAve fldName fldAve
Sand 4 Sand 4 Sand 4
Sand 4 Water 3.8 Computer 3.35
Water 3.7 Soda 3.43
Water 4 Computer 3.35
Water 3.7 Phone 3.43
Soda 3.7 Pencil 3.75
Soda 3.3
Soda 3.3
Computer 3.7
Computer 3
Phone 3
Phone 3.3
Phone 4
Pencil 4
Pencil 4
Pencil 3
Like I said I'm very new to Access and I am just trying things out. If you recommend setting up the query a different way Im open to anything really. The more I learn the better.
To get the average for each fieldname, just do this in a query:
SELECT FieldName, Avg(FieldNum) as AvgQty
FROM MyTable
GROUP BY FieldName
ORDER BY FieldName
This will also sort the fieldname column for you.
EDIT:
I think you can do what you asked for in your comment, but you will need a separate query based on the one above. You'll need a UNION query to do it. Something like:
SELECT Top 1 FieldName, AvgQty
FROM Query1
ORDER BY AvgQty ASC
UNION ALL
SELECT Top 1 FieldName, AvgQty
FROM Query1
ORDER BY AvgQty DESC
I'm doing that off the top of my head, so it may not be perfect.
As for formatting the field, do a google on "VBA Format Number" and you should be able to find some examples. I think it might make the above query look something like:
SELECT Top 1 FieldName, Format(AvgQty, "##.#") as AvgQty1
FROM Query1
ORDER BY AvgQty ASC
UNION ALL
SELECT Top 1 FieldName, Format(AvgQty, "##.#") as AvgQty1
FROM Query1
ORDER BY AvgQty DESC
I have a table equipment with columns name, description, status
This is how my table looks like when I display all rows:
id name description status
1 shovel shiny shovel 1
2 shovel shiny shovel 1
3 shovel shiny shovel 0
4 hammer big hammer 1
5 hammer big hammer 0
This is the SQL statement I have right now:
SELECT equipment.name, equipment.description, COUNT(*) AS stock
FROM equipment
GROUP BY equipment.name
and it shows the following:
name description stock
shovel shiny shovel 3
hammer big hammer 2
What I want is to display another column showing the number of equipment that has a status of 1
name description stock available
shovel shiny shovel 3 2
hammer big hammer 2 1
You are almost there: all you need is to sum up the status fields, like this:
SELECT
equipment.name,
equipment.description,
COUNT(*) AS stock,
SUM(status) as available
FROM equipment
GROUP BY
equipment.name,
equipment.description
The trick here (that will work in SQL Server and MySQL) is to use conditional SUM() instead of COUNT()
SELECT ..., SUM(WHEN CASE status = 1 THEN 1 ELSE 0 END) as available
If status can be only 1 or 0 then you can just total it:
SELECT ..., SUM(status) as available
I want to write a web application to order my photos. Instead of putting them into categories, I want to add tags to certain pictures. I thought of having 2 tables, one for the images:
uniqueID imagename
1 photo1.jpg
2 photo2.jpg
3 photo3.jpeg
4 pic4.jpeg
and one table for the tags:
ID tag
1 California
1 Peter
1 beach
2 California
2 L.A.
2 Peter
3 California
3 Susan
4 Kansas
4 Claudia
After starting the application the tags are shown in a size accoring to the number of occurences in the database. When I click on a tag (e.g. "California") all the remaining tags of images, that also have the selected tag should be shown on the next page (here: "Peter", "beach", "L.A.", "Susan" but NOT "Kansas" and "Claudia"). When I afterwards click for example on the tag "peter" all the remaining tags of photo 1 and 2 should be shown ("beach", "L.A.").
Is it possible to realize those two things with a single query?
Select image-names from the image table, that have all selected tags in the the tag-table
Select all remaining tags and their COUNT() for those images (IDs) that also have the selected tags in the tag-table.
Thanks for your help
Sven
For 1) You must use a SELECT query with JOINS. For example:
SELECT *
FROM images i
INNER JOIN categories c
ON i.id = c.id
For 2) I'm not quite sure I understand what you mean by remaining tags.
I am considering how to structure my MySQL database in e-commerce solution. To be more specific I am looking at the product structure.
These are the tables I have come up with so far. What do you think?
Explanation of structure
The application is multilingual. Therefore the product table are split in 2 tables.
If a products has e.g. 2 variants (Small, Medium) a total of 3 rows will be inserted. This is because each variant can have different information for each variant. When the product is shown on the webpage product 1 will be shown with a drop down box with Small & Medium. A product with no variants will naturally only insert 1 row.
products
id master product_number
1 0 123
2 1 456
3 1 678
products_descriptions
id product_id country_code image name description vat price
1 1 en-us image.jpg t-shirt Nice t-shirt 25 19.99
2 2 en-us image.jpg t-shirt Nice t-shirt 25 19.99
3 3 en-us image.jpg t-shirt Nice t-shirt 25 19.99
products_to_options
product_id option_id
2 1
3 2
options
id name
1 Small
2 Medium
Your Products table is schizophrenic, its entity is sometimes Product and sometimes Variant. This leads to very cumbersome behavior. For example, you'd like the question "how many different products do we have?" be answered by select count(*) from products, but here this gives the wrong answer, to get the correct answer you have to know the Magic Number 0 and query select count (*) from products where master=0. "List all products and how many variants we have for each" is another query that should be straightforward but now isn't. There are other anomalies, like the fact that the first line in products_descriptions is a shirt that has a price and a picture but no size (size is stored in the variants, but they have prices and pictures of their own).
Your problem sounds like you have products in two contexts: (1) something that can be displayed as an item in your store, and (2) something that can be ordered by your customer. (1) probably has a name like "Halloween T-Shirt" or so, and it probably has an image that the customer sees. (2) is what the customer orders, so it has a (1), but also a variant specification like "small" or maybe a color "red". It probably has a price, too, and an order_id so your shop can know what specific item to ship.
You should give each context an entity. Here's how i'd do it
displayable_product
id name
1 "Baseball Cap"
2 "T-Shirt"
orderable_product
id d_product_id order_id size color price
1 1 123 red 9.99
2 2 456 small 19.99
3 2 789 medium 21.99
displayable_content
id d_product_id locale name image
1 1 en_US "Baseball Cap" baseballcap.jpg
2 1 es_US "Gorra de Beisbol" baseballcap.jpg
3 2 en_US "Nice T-Shirt" nicetshirt.jpg
4 2 es_US "Camiseta" nicetshirt.jpg
You should probably use locale instead of country in the display tables to account for countries with more than one language (USA, Switzerland, and others), and you might separate the size and color into its own variants table. And if you need country-dependent data on the orderables (like different prices/currencies for shipping to different countries), you'd have to extract a country-dependent orderable_content table, too.